From cf37b5ef5aae7fecf8dc7cca2c4fb99b66ba6e8b Mon Sep 17 00:00:00 2001 From: ChenTengLong <1010054754@qq.com> Date: Tue, 21 Jun 2022 10:53:50 +0800 Subject: [PATCH] add utils --- utils/common.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 utils/common.go diff --git a/utils/common.go b/utils/common.go new file mode 100644 index 0000000..c91562c --- /dev/null +++ b/utils/common.go @@ -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 +} \ No newline at end of file