package config import ( "fmt" "github.com/beego/beego/v2/core/logs" "github.com/beego/beego/v2/server/web" ) const ( SPLIT = "." ) type Config interface { GetConfig() interface{} InitConfig() } type BaseConfig struct { prefix string config map[string]string } func (b *BaseConfig) GetString(key string) string { value, err := web.AppConfig.String(fmt.Sprintf("%s%s%s", b.prefix, SPLIT, key)) if err != nil { return "" } return value } type Instance func() Config var configs = make(map[string]Instance) func GetConfig(name string) (config Config) { instanceFunc, ok := configs[name] if !ok { logs.Error("配置信息不存在", name) return nil } config = instanceFunc() config.InitConfig() return config } func Register(name string, adapter Instance) { if adapter == nil { panic("cache: Register adapter is nil") } if _, ok := configs[name]; ok { panic("cache: Register called twice for adapter " + name) } configs[name] = adapter }