Simple hosts file management in Go (golang).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

30 lines
495 B

  1. package goodhosts
  2. import (
  3. "os"
  4. "path/filepath"
  5. )
  6. // NewHosts Return a new instance of ``Hosts``.
  7. func NewHosts(sectionName string) (Hosts, error) {
  8. osHostsFilePath := ""
  9. if os.Getenv("HOSTS_PATH") == "" {
  10. osHostsFilePath = os.ExpandEnv(filepath.FromSlash(hostsFilePath))
  11. } else {
  12. osHostsFilePath = os.Getenv("HOSTS_PATH")
  13. }
  14. hosts := Hosts{
  15. Path: osHostsFilePath,
  16. Section: sectionName,
  17. }
  18. err := hosts.Load()
  19. if err != nil {
  20. return hosts, err
  21. }
  22. return hosts, nil
  23. }