owl-blogs/app/config_register.go

34 lines
673 B
Go
Raw Normal View History

2023-07-22 18:34:17 +00:00
package app
type ConfigRegister struct {
configs map[string]interface{}
}
2023-07-22 19:12:53 +00:00
type RegisteredConfig struct {
Name string
Config interface{}
}
2023-07-22 18:34:17 +00:00
func NewConfigRegister() *ConfigRegister {
return &ConfigRegister{configs: map[string]interface{}{}}
}
func (r *ConfigRegister) Register(name string, config interface{}) {
r.configs[name] = config
}
2023-07-22 19:12:53 +00:00
func (r *ConfigRegister) Configs() []RegisteredConfig {
var configs []RegisteredConfig
for name, config := range r.configs {
configs = append(configs, RegisteredConfig{
Name: name,
Config: config,
})
}
return configs
}
func (r *ConfigRegister) GetConfig(name string) interface{} {
return r.configs[name]
}