add reload funtion when execute command was changed

This commit is contained in:
liangzy 2020-07-06 11:29:59 +08:00
parent 852b176c93
commit 89d91c6256

View File

@ -6,6 +6,7 @@ import (
_ "github.com/lib/pq" _ "github.com/lib/pq"
"golib.gaore.com/GaoreGo/grconfig" "golib.gaore.com/GaoreGo/grconfig"
"golib.gaore.com/GaoreGo/grlogs" "golib.gaore.com/GaoreGo/grlogs"
"path"
) )
const DEFAULT = "default" const DEFAULT = "default"
@ -33,9 +34,12 @@ func (d *DbItem) Dsn() string {
} }
func init() { func init() {
Reload()
}
func Reload(dir ...string) {
var err error var err error
var configer *grconfig.Configer
logger := grlogs.GetAli("sql") logger := grlogs.GetAli("sql")
defer func() { defer func() {
@ -44,16 +48,21 @@ func init() {
} }
}() }()
dsns, err := GetDsn() if len(dir) == 0 {
configer = grconfig.New("conf/")
} else {
dir = append(dir, "conf/")
configer = grconfig.New(path.Join(dir...))
}
dsns, err := GetDsn(configer)
if err = LoadXorm(dsns); err != nil { if err = LoadXorm(dsns); err != nil {
logger.Critical(err.Error()) logger.Critical(err.Error())
} }
} }
func GetDsn() (DsnList map[string]dsnConfig, err error) { func GetDsn(configer *grconfig.Configer) (DsnList map[string]dsnConfig, err error) {
var items map[string]*DbItem var items map[string]*DbItem
DsnList = make(map[string]dsnConfig) DsnList = make(map[string]dsnConfig)
configer := grconfig.New("conf/")
err = configer.Item("db", &items) err = configer.Item("db", &items)
if err != nil { if err != nil {
return return