mirror of https://github.com/shunfei/cronsun
conf: 配置文件路径可指定
parent
356654c56b
commit
0ed5ceda39
15
conf/conf.go
15
conf/conf.go
|
@ -1,6 +1,7 @@
|
||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -9,10 +10,12 @@ import (
|
||||||
"sunteng/commons/confutil"
|
"sunteng/commons/confutil"
|
||||||
"sunteng/commons/db/imgo"
|
"sunteng/commons/db/imgo"
|
||||||
"sunteng/commons/log"
|
"sunteng/commons/log"
|
||||||
"sunteng/commons/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
confFile = flag.String("conf",
|
||||||
|
"conf/files/base.json", "config file path")
|
||||||
|
|
||||||
Config = new(Conf)
|
Config = new(Conf)
|
||||||
initialized bool
|
initialized bool
|
||||||
)
|
)
|
||||||
|
@ -22,10 +25,8 @@ func Init() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.Root = util.CurDir()
|
flag.Parse()
|
||||||
|
err := confutil.LoadExtendConf(*confFile, Config)
|
||||||
confFile := path.Join(Config.Root, "files", "base.json")
|
|
||||||
err := confutil.LoadExtendConf(confFile, Config)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -39,15 +40,11 @@ func Init() error {
|
||||||
Config.Proc = cleanKeyPrefix(Config.Proc)
|
Config.Proc = cleanKeyPrefix(Config.Proc)
|
||||||
Config.Group = cleanKeyPrefix(Config.Group)
|
Config.Group = cleanKeyPrefix(Config.Group)
|
||||||
|
|
||||||
Config.Root = path.Join(Config.Root, "..")
|
|
||||||
|
|
||||||
initialized = true
|
initialized = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
Root string // 项目根目录
|
|
||||||
|
|
||||||
Proc string // proc 路径
|
Proc string // proc 路径
|
||||||
Cmd string // cmd 路径
|
Cmd string // cmd 路径
|
||||||
Group string // 节点分组
|
Group string // 节点分组
|
||||||
|
|
Loading…
Reference in New Issue