Skip to content

Commit

Permalink
add utils
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanshaoye committed Jun 21, 2022
1 parent 72f5709 commit cf37b5e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions utils/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package utils

import (
"os"
"os/user"
"path/filepath"
)

var dirPath string

func getHomeDir() string {
path, err := os.UserHomeDir()
if err == nil {
return path
}
user, err := user.Current()
if err == nil {
return user.HomeDir
}
path, _ = filepath.Abs("~")
return path
}

func makeLogDir() {
home := getHomeDir()
dirPath = home + "/collctionlogs"
os.MkdirAll(dirPath, 0766)
}

func GetLogDir() string {
makeLogDir()
return dirPath
}

0 comments on commit cf37b5e

Please sign in to comment.