mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-07 20:45:53 +08:00
fix env conf load.
This commit is contained in:
parent
bfea93312a
commit
449ae96c8f
@ -161,76 +161,80 @@ func Get() *Config {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// type convert tools
|
if hasEnvironmentConf {
|
||||||
toInt64 := func(str string) int64 {
|
// type convert tools
|
||||||
i, _ := strconv.ParseInt(str, 10, 64)
|
toInt64 := func(str string) int64 {
|
||||||
return i
|
i, _ := strconv.ParseInt(str, 10, 64)
|
||||||
}
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
// load config from environment variable
|
// load config from environment variable
|
||||||
global.SetAtDefault(&config.Account.Uin, toInt64(os.Getenv("GCQ_UIN")), int64(0))
|
global.SetAtDefault(&config.Account.Uin, toInt64(os.Getenv("GCQ_UIN")), int64(0))
|
||||||
global.SetAtDefault(&config.Account.Password, os.Getenv("GCQ_PWD"), "")
|
global.SetAtDefault(&config.Account.Password, os.Getenv("GCQ_PWD"), "")
|
||||||
global.SetAtDefault(&config.Account.Status, int32(toInt64(os.Getenv("GCQ_STATUS"))), int32(0))
|
global.SetAtDefault(&config.Account.Status, int32(toInt64(os.Getenv("GCQ_STATUS"))), int32(0))
|
||||||
global.SetAtDefault(&config.Account.ReLogin.Disabled, !global.EnsureBool(os.Getenv("GCQ_RELOGIN"), false), false)
|
global.SetAtDefault(&config.Account.ReLogin.Disabled, !global.EnsureBool(os.Getenv("GCQ_RELOGIN"), false), false)
|
||||||
global.SetAtDefault(&config.Account.ReLogin.Delay, uint(toInt64(os.Getenv("GCQ_RELOGIN_DELAY"))), uint(0))
|
global.SetAtDefault(&config.Account.ReLogin.Delay, uint(toInt64(os.Getenv("GCQ_RELOGIN_DELAY"))), uint(0))
|
||||||
global.SetAtDefault(&config.Account.ReLogin.MaxTimes, uint(toInt64(os.Getenv("GCQ_RELOGIN_MAX_TIMES"))), uint(0))
|
global.SetAtDefault(&config.Account.ReLogin.MaxTimes, uint(toInt64(os.Getenv("GCQ_RELOGIN_MAX_TIMES"))), uint(0))
|
||||||
dbConf := &LevelDBConfig{Enable: global.EnsureBool(os.Getenv("GCQ_LEVELDB"), true)}
|
dbConf := &LevelDBConfig{Enable: global.EnsureBool(os.Getenv("GCQ_LEVELDB"), true)}
|
||||||
config.Database = make(map[string]yaml.Node)
|
if config.Database == nil {
|
||||||
config.Database["leveldb"] = func() yaml.Node {
|
config.Database = make(map[string]yaml.Node)
|
||||||
n := &yaml.Node{}
|
|
||||||
_ = n.Encode(dbConf)
|
|
||||||
return *n
|
|
||||||
}()
|
|
||||||
accessTokenEnv := os.Getenv("GCQ_ACCESS_TOKEN")
|
|
||||||
if os.Getenv("GCQ_HTTP_PORT") != "" {
|
|
||||||
node := &yaml.Node{}
|
|
||||||
httpConf := &HTTPServer{
|
|
||||||
Host: "0.0.0.0",
|
|
||||||
Port: 5700,
|
|
||||||
MiddleWares: MiddleWares{
|
|
||||||
AccessToken: accessTokenEnv,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
global.SetExcludeDefault(&httpConf.Disabled, global.EnsureBool(os.Getenv("GCQ_HTTP_DISABLE"), false), false)
|
config.Database["leveldb"] = func() yaml.Node {
|
||||||
global.SetExcludeDefault(&httpConf.Host, os.Getenv("GCQ_HTTP_HOST"), "")
|
n := &yaml.Node{}
|
||||||
global.SetExcludeDefault(&httpConf.Port, int(toInt64(os.Getenv("GCQ_HTTP_PORT"))), 0)
|
_ = n.Encode(dbConf)
|
||||||
if os.Getenv("GCQ_HTTP_POST_URL") != "" {
|
return *n
|
||||||
httpConf.Post = append(httpConf.Post, struct {
|
}()
|
||||||
URL string `yaml:"url"`
|
accessTokenEnv := os.Getenv("GCQ_ACCESS_TOKEN")
|
||||||
Secret string `yaml:"secret"`
|
if os.Getenv("GCQ_HTTP_PORT") != "" {
|
||||||
}{os.Getenv("GCQ_HTTP_POST_URL"), os.Getenv("GCQ_HTTP_POST_SECRET")})
|
node := &yaml.Node{}
|
||||||
|
httpConf := &HTTPServer{
|
||||||
|
Host: "0.0.0.0",
|
||||||
|
Port: 5700,
|
||||||
|
MiddleWares: MiddleWares{
|
||||||
|
AccessToken: accessTokenEnv,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
global.SetExcludeDefault(&httpConf.Disabled, global.EnsureBool(os.Getenv("GCQ_HTTP_DISABLE"), false), false)
|
||||||
|
global.SetExcludeDefault(&httpConf.Host, os.Getenv("GCQ_HTTP_HOST"), "")
|
||||||
|
global.SetExcludeDefault(&httpConf.Port, int(toInt64(os.Getenv("GCQ_HTTP_PORT"))), 0)
|
||||||
|
if os.Getenv("GCQ_HTTP_POST_URL") != "" {
|
||||||
|
httpConf.Post = append(httpConf.Post, struct {
|
||||||
|
URL string `yaml:"url"`
|
||||||
|
Secret string `yaml:"secret"`
|
||||||
|
}{os.Getenv("GCQ_HTTP_POST_URL"), os.Getenv("GCQ_HTTP_POST_SECRET")})
|
||||||
|
}
|
||||||
|
_ = node.Encode(httpConf)
|
||||||
|
config.Servers = append(config.Servers, map[string]yaml.Node{"http": *node})
|
||||||
}
|
}
|
||||||
_ = node.Encode(httpConf)
|
if os.Getenv("GCQ_WS_PORT") != "" {
|
||||||
config.Servers = append(config.Servers, map[string]yaml.Node{"http": *node})
|
node := &yaml.Node{}
|
||||||
}
|
wsServerConf := &WebsocketServer{
|
||||||
if os.Getenv("GCQ_WS_PORT") != "" {
|
Host: "0.0.0.0",
|
||||||
node := &yaml.Node{}
|
Port: 6700,
|
||||||
wsServerConf := &WebsocketServer{
|
MiddleWares: MiddleWares{
|
||||||
Host: "0.0.0.0",
|
AccessToken: accessTokenEnv,
|
||||||
Port: 6700,
|
},
|
||||||
MiddleWares: MiddleWares{
|
}
|
||||||
AccessToken: accessTokenEnv,
|
global.SetExcludeDefault(&wsServerConf.Disabled, global.EnsureBool(os.Getenv("GCQ_WS_DISABLE"), false), false)
|
||||||
},
|
global.SetExcludeDefault(&wsServerConf.Host, os.Getenv("GCQ_WS_HOST"), "")
|
||||||
|
global.SetExcludeDefault(&wsServerConf.Port, int(toInt64(os.Getenv("GCQ_WS_PORT"))), 0)
|
||||||
|
_ = node.Encode(wsServerConf)
|
||||||
|
config.Servers = append(config.Servers, map[string]yaml.Node{"ws": *node})
|
||||||
}
|
}
|
||||||
global.SetExcludeDefault(&wsServerConf.Disabled, global.EnsureBool(os.Getenv("GCQ_WS_DISABLE"), false), false)
|
if os.Getenv("GCQ_RWS_API") != "" || os.Getenv("GCQ_RWS_EVENT") != "" || os.Getenv("GCQ_RWS_UNIVERSAL") != "" {
|
||||||
global.SetExcludeDefault(&wsServerConf.Host, os.Getenv("GCQ_WS_HOST"), "")
|
node := &yaml.Node{}
|
||||||
global.SetExcludeDefault(&wsServerConf.Port, int(toInt64(os.Getenv("GCQ_WS_PORT"))), 0)
|
rwsConf := &WebsocketReverse{
|
||||||
_ = node.Encode(wsServerConf)
|
MiddleWares: MiddleWares{
|
||||||
config.Servers = append(config.Servers, map[string]yaml.Node{"ws": *node})
|
AccessToken: accessTokenEnv,
|
||||||
}
|
},
|
||||||
if os.Getenv("GCQ_RWS_API") != "" || os.Getenv("GCQ_RWS_EVENT") != "" || os.Getenv("GCQ_RWS_UNIVERSAL") != "" {
|
}
|
||||||
node := &yaml.Node{}
|
global.SetExcludeDefault(&rwsConf.Disabled, global.EnsureBool(os.Getenv("GCQ_RWS_DISABLE"), false), false)
|
||||||
rwsConf := &WebsocketReverse{
|
global.SetExcludeDefault(&rwsConf.API, os.Getenv("GCQ_RWS_API"), "")
|
||||||
MiddleWares: MiddleWares{
|
global.SetExcludeDefault(&rwsConf.Event, os.Getenv("GCQ_RWS_EVENT"), "")
|
||||||
AccessToken: accessTokenEnv,
|
global.SetExcludeDefault(&rwsConf.Universal, os.Getenv("GCQ_RWS_UNIVERSAL"), "")
|
||||||
},
|
_ = node.Encode(rwsConf)
|
||||||
|
config.Servers = append(config.Servers, map[string]yaml.Node{"ws-reverse": *node})
|
||||||
}
|
}
|
||||||
global.SetExcludeDefault(&rwsConf.Disabled, global.EnsureBool(os.Getenv("GCQ_RWS_DISABLE"), false), false)
|
|
||||||
global.SetExcludeDefault(&rwsConf.API, os.Getenv("GCQ_RWS_API"), "")
|
|
||||||
global.SetExcludeDefault(&rwsConf.Event, os.Getenv("GCQ_RWS_EVENT"), "")
|
|
||||||
global.SetExcludeDefault(&rwsConf.Universal, os.Getenv("GCQ_RWS_UNIVERSAL"), "")
|
|
||||||
_ = node.Encode(rwsConf)
|
|
||||||
config.Servers = append(config.Servers, map[string]yaml.Node{"ws-reverse": *node})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return config
|
return config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user