summaryrefslogtreecommitdiffstats
path: root/golib/filepath.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-09-22 15:57:14 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-09-22 15:57:14 +0200
commitf668c6cc855dae530ac71d4ef82e78ecc20a8f84 (patch)
tree137dc7c1d2cb9dc59c4e93f42caaffffb3377568 /golib/filepath.go
parent59a1e17527c91c1cddc344ec4273a905336eecdd (diff)
Added GetUserHomev0.1.1
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'golib/filepath.go')
-rw-r--r--golib/filepath.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/golib/filepath.go b/golib/filepath.go
index b27ac6f..c91f63d 100644
--- a/golib/filepath.go
+++ b/golib/filepath.go
@@ -108,3 +108,17 @@ func PathNormalize(p string) string {
res = strings.Replace(res, "\\", "/", -1)
return filepath.Clean(res)
}
+
+// GetUserHome returns the user's home directory or empty string on error
+func GetUserHome() string {
+ if usr, err := user.Current(); err == nil && usr != nil && usr.HomeDir != "" {
+ return usr.HomeDir
+ }
+ for _, p := range []string{"HOME", "HomePath"} {
+ if h := os.Getenv(p); h != "" {
+ return h
+ }
+ }
+
+ return ""
+}