增加工作目录配置功能
This commit is contained in:
parent
b2ddac9abc
commit
77d7ef9714
3 changed files with 17 additions and 4 deletions
2
main.go
2
main.go
|
@ -16,7 +16,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "配置文件路径")
|
||||
flag.StringVar(&confPath, "c", util.RelativeExecutablePath("conf.ini"), "配置文件路径")
|
||||
flag.BoolVar(&isEject, "eject", false, "导出内置静态资源")
|
||||
flag.StringVar(&scriptName, "database-script", "", "运行内置数据库助手脚本")
|
||||
flag.Parse()
|
||||
|
|
|
@ -26,6 +26,7 @@ type system struct {
|
|||
Debug bool
|
||||
SessionSecret string
|
||||
HashIDSalt string
|
||||
DataPath string
|
||||
}
|
||||
|
||||
type ssl struct {
|
||||
|
|
|
@ -48,11 +48,23 @@ func FormSlash(old string) string {
|
|||
return path.Clean(strings.ReplaceAll(old, "\\", "/"))
|
||||
}
|
||||
|
||||
// RelativePath 获取相对工作目录的路径
|
||||
// RelativeExecutablePath 获取相对可执行文件的路径
|
||||
func RelativeExecutablePath(name string) string {
|
||||
if filepath.IsAbs(name) {
|
||||
return name
|
||||
}
|
||||
e, _ := os.Executable()
|
||||
return filepath.Join(filepath.Dir(e), name)
|
||||
}
|
||||
|
||||
//RelativePath 获取相对路径
|
||||
func RelativePath(name string) string {
|
||||
if filepath.IsAbs(name) {
|
||||
return name
|
||||
}
|
||||
e, _ := os.Getwd()
|
||||
return filepath.Join(e, name)
|
||||
if conf.SystemConfig.DataPath != "" {
|
||||
return filepath.Join(conf.SystemConfig.DataPath, name)
|
||||
} else {
|
||||
return RelativeExecutablePath(name)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue