77 "github.com/gookit/goutil/internal/comfunc"
88)
99
10- // MustFindUser must find an system user by name
10+ // MustFindUser must find a system user by name
1111func MustFindUser (uname string ) * user.User {
1212 u , err := user .Lookup (uname )
1313 if err != nil {
@@ -16,24 +16,22 @@ func MustFindUser(uname string) *user.User {
1616 return u
1717}
1818
19- // LoginUser must get current user
19+ // LoginUser must get current user, will panic if error
2020func LoginUser () * user.User {
2121 return CurrentUser ()
2222}
2323
24- // CurrentUser must get current user
24+ // CurrentUser must get current user, will panic if error
2525func CurrentUser () * user.User {
26- // check $HOME/.terminfo
2726 u , err := user .Current ()
2827 if err != nil {
2928 panic (err )
3029 }
3130 return u
3231}
3332
34- // UHomeDir get user home dir path.
33+ // UHomeDir get user home dir path, ignore error. (by user.Current)
3534func UHomeDir () string {
36- // check $HOME/.terminfo
3735 u , err := user .Current ()
3836 if err != nil {
3937 return ""
@@ -42,37 +40,32 @@ func UHomeDir() string {
4240}
4341
4442// homeDir cache
45- var homeDir string
43+ var _homeDir string
4644
47- // UserHomeDir is alias of os.UserHomeDir, but ignore error
45+ // UserHomeDir is alias of os.UserHomeDir, but ignore error.(by os.UserHomeDir)
4846func UserHomeDir () string {
49- if homeDir == "" {
50- homeDir , _ = os .UserHomeDir ()
47+ if _homeDir == "" {
48+ _homeDir , _ = os .UserHomeDir ()
5149 }
52- return homeDir
50+ return _homeDir
5351}
5452
5553// HomeDir get user home dir path.
56- func HomeDir () string {
57- return UserHomeDir ()
58- }
54+ func HomeDir () string { return UserHomeDir () }
5955
60- // UserDir will prepend user home dir to subPath
61- func UserDir (subPath string ) string {
62- dir := UserHomeDir ()
63- return dir + "/" + subPath
56+ // UserDir will prepend user home dir to subPaths
57+ func UserDir (subPaths ... string ) string {
58+ return comfunc .JoinPaths2 (UserHomeDir (), subPaths )
6459}
6560
66- // UserCacheDir will prepend user `$HOME/.cache` to subPath
67- func UserCacheDir (subPath string ) string {
68- dir := UserHomeDir ()
69- return dir + "/.cache/" + subPath
61+ // UserCacheDir will prepend user `$HOME/.cache` to subPaths
62+ func UserCacheDir (subPaths ... string ) string {
63+ return comfunc .JoinPaths3 (UserHomeDir (), ".cache" , subPaths )
7064}
7165
7266// UserConfigDir will prepend user `$HOME/.config` to subPath
73- func UserConfigDir (subPath string ) string {
74- dir := UserHomeDir ()
75- return dir + "/.config/" + subPath
67+ func UserConfigDir (subPaths ... string ) string {
68+ return comfunc .JoinPaths3 (UserHomeDir (), ".cache" , subPaths )
7669}
7770
7871// ExpandPath will parse `~` as user home dir path.
0 commit comments