28 lines
579 B
Go
28 lines
579 B
Go
//go:build windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
)
|
|
|
|
func getHostsFileLocation() (string, error) {
|
|
//return "hosts", nil
|
|
var hostsFileLocation string
|
|
value, envExists := os.LookupEnv("SystemRoot")
|
|
if envExists {
|
|
hostsFileLocation = value + "\\System32\\drivers\\etc\\hosts"
|
|
} else {
|
|
hostsFileLocation = "C:\\Windows\\System32\\drivers\\etc\\hosts"
|
|
}
|
|
exists, err := fileExists(hostsFileLocation)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if exists == false {
|
|
return "", errors.New("file does not exist: " + hostsFileLocation)
|
|
}
|
|
return hostsFileLocation, nil
|
|
}
|