Export $HOME lookup to pkg/homedir
Signed-off-by: Ahmet Alp Balkan <ahmetb@microsoft.com>
This commit is contained in:
parent
193aa34569
commit
2c44d13150
3 changed files with 34 additions and 0 deletions
16
homedir/homedir.go
Normal file
16
homedir/homedir.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package homedir
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// Get returns the home directory of the current user with the help of
|
||||
// environment variables depending on the target operating system.
|
||||
// Returned path should be used with "path/filepath" to form new paths.
|
||||
func Get() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return os.Getenv("USERPROFILE")
|
||||
}
|
||||
return os.Getenv("HOME")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue