package library import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" ) const ( game_libraryhero = "game_libraryhero.json" game_libraryfetter = "game_libraryfetter.json" ) ///配置管理基础组件 type configureComp struct { modules.MCompConfigure } //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.MCompConfigure.Init(service, module, comp, options) //err = this.LoadConfigure(game_libraryhero, cfg.NewGameLibraryHero) err = this.LoadMultiConfigure(map[string]interface{}{ game_libraryhero: cfg.NewGameLibraryHero, game_libraryfetter: cfg.NewGameLibraryFetter, }) return } //加载多个配置文件 func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) { for k, v := range confs { err = configure.RegisterConfigure(k, v, nil) if err != nil { log.Errorf("配置文件:%s解析失败!", k) break } } return } //读取配置数据 func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } func (this *configureComp) GetLibraryHero(hid string) (data *cfg.GameLibraryHeroData) { if v, err := this.GetConfigure(game_libraryhero); err == nil { if configure, ok := v.(*cfg.GameLibraryHero); ok { data = configure.Get(hid) return } } else { log.Errorf("get game_challenge conf err:%v", err) } return } func (this *configureComp) GetLibraryFetter(fid int32) (data *cfg.GameLibraryFetterData) { if v, err := this.GetConfigure(game_libraryfetter); err == nil { if configure, ok := v.(*cfg.GameLibraryFetter); ok { data = configure.Get(fid) return } } else { log.Errorf("get game_challenge conf err:%v", err) } return }