70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package modules
|
|
|
|
import (
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/core/cbase"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
const (
|
|
game_global = "game_global.json"
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type MCompConfigure struct {
|
|
cbase.ModuleCompBase
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *MCompConfigure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleCompBase.Init(service, module, comp, options)
|
|
err = this.LoadConfigure(game_global, cfg.NewGame_global)
|
|
return
|
|
}
|
|
|
|
//加载一个配置文件
|
|
func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) {
|
|
return configure.RegisterConfigure(name, fn)
|
|
}
|
|
|
|
//加载多个配置文件
|
|
func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
|
for k, v := range confs {
|
|
err = configure.RegisterConfigure(k, v)
|
|
if err != nil {
|
|
log.Errorf("配置文件:%s解析失败!", k)
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取配置数据
|
|
func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
//全局配置
|
|
func (this *MCompConfigure) GetGlobalConf(key string) string {
|
|
if v, err := this.GetConfigure(game_global); err != nil {
|
|
log.Errorf("get global conf err:%v", err)
|
|
return ""
|
|
} else {
|
|
var (
|
|
configure *cfg.Game_global
|
|
ok bool
|
|
)
|
|
if configure, ok = v.(*cfg.Game_global); !ok {
|
|
log.Errorf("%T no is *cfg.Game_global", v)
|
|
return ""
|
|
}
|
|
|
|
if v, ok := configure.GetDataMap()[key]; ok {
|
|
return v.Var
|
|
}
|
|
}
|
|
return ""
|
|
}
|