Use os.UserHomeDir to determine home directory

Go provides this since Go 1.12; no need to reinvent the wheel.
This commit is contained in:
Andrew Ayer 2022-10-08 18:17:35 -04:00
parent 3d1bdb2b60
commit 33ebbdfd07
1 changed files with 4 additions and 9 deletions

View File

@ -16,7 +16,6 @@ import (
"fmt"
"log"
"os"
"os/user"
"path/filepath"
"sync"
@ -41,15 +40,11 @@ var state *State
var printMutex sync.Mutex
func homedir() string {
home := os.Getenv("HOME")
if home != "" {
return home
homedir, err := os.UserHomeDir()
if err != nil {
panic(fmt.Errorf("unable to determine home directory: %w", err))
}
user, err := user.Current()
if err == nil {
return user.HomeDir
}
panic("Unable to determine home directory")
return homedir
}
func DefaultStateDir(programName string) string {