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