-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsHelper.go
More file actions
executable file
·43 lines (36 loc) · 910 Bytes
/
settingsHelper.go
File metadata and controls
executable file
·43 lines (36 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"log"
"os"
"path/filepath"
"runtime"
"strings"
)
type Settings struct {
SettingPath string
}
func NewSettings() Settings {
var settings Settings
_, fullFilename, _, _ := runtime.Caller(0)
// 获取带扩展名的文件名
filenameWithSuffix := filepath.Base(fullFilename)
// 仅仅获取当前文件夹
dir := strings.TrimSuffix(fullFilename, filenameWithSuffix)
settings.SettingPath = dir
return settings
}
func (s *Settings) SetSettingPath(pathStr string) bool {
if err := os.MkdirAll(pathStr, 0777); err != nil{
log.Println(err.Error())
return false
}
s.SettingPath = pathStr
return true
}
func (s *Settings) ResetSettingPath() bool {
_, fullFilename, _, _ := runtime.Caller(0)
filenameWithSuffix := filepath.Base(fullFilename)
pathStr := strings.TrimSuffix(fullFilename, filenameWithSuffix)
s.SettingPath = pathStr
return true
}