From 3ae3b6f039c1f1cf23b3aa85eef43486d6cfacfc Mon Sep 17 00:00:00 2001 From: William Carroll Date: Tue, 11 Feb 2020 17:01:28 +0000 Subject: Support utils.HomeDir/0 Support function for returning the home directory of the current user. --- gopkgs/utils/utils.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gopkgs') 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 { -- cgit 1.4.1