Update getHomeDir() to use "os/user"

os.Getenv("HOME") doesn't work properly on Windows (and maybe other systems?) and the package "os/user" gives us a convenient way to find the home directory for every OS.
This commit is contained in:
filoozom 2014-03-02 16:07:12 +01:00
parent 192117dc11
commit 23593c3d20

11
main.go
View File

@ -11,6 +11,7 @@ import (
_ "net/http/pprof"
"os"
"os/exec"
"os/user"
"path"
"runtime"
"runtime/debug"
@ -561,9 +562,13 @@ func expandTilde(p string) string {
}
func getHomeDir() string {
home := os.Getenv("HOME")
if home == "" {
usr, err := user.Current()
if err != nil {
fatalln(err)
}
if usr.HomeDir == "" {
fatalln("No home directory?")
}
return home
return usr.HomeDir
}