diff options
author | William Carroll <wpcarro@gmail.com> | 2020-02-11T17·01+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-02-11T17·11+0000 |
commit | 3ae3b6f039c1f1cf23b3aa85eef43486d6cfacfc (patch) | |
tree | 5edbd50ab94a35fc46c1895c376e343be025e519 /gopkgs/utils/utils.go | |
parent | 825d6f2c65d9d167152d11e7cd9ea62874e9f715 (diff) |
Support utils.HomeDir/0
Support function for returning the home directory of the current user.
Diffstat (limited to 'gopkgs/utils/utils.go')
-rw-r--r-- | gopkgs/utils/utils.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gopkgs/utils/utils.go b/gopkgs/utils/utils.go index 404fd8bf0a12..7ac9defa6f0f 100644 --- a/gopkgs/utils/utils.go +++ b/gopkgs/utils/utils.go @@ -7,8 +7,18 @@ import ( "log" "net/http" "net/http/httputil" + "os/user" ) +// Return the absolute path to the current uesr's home directory. +func HomeDir() string { + user, err := user.Current() + if err != nil { + log.Fatal(err) + } + return user.HomeDir +} + // Call log.Fatal with `err` when it's not nil. func FailOn(err error) { if err != nil { |