owl-blogs/app/config_register.go

41 lines
872 B
Go
Raw Normal View History

2023-07-22 18:34:17 +00:00
package app
2024-02-21 19:03:18 +00:00
import "owl-blogs/domain/model"
type AppConfig interface {
Form(binSvc model.BinaryStorageInterface) string
ParseFormData(data model.HttpFormData, binSvc model.BinaryStorageInterface) (AppConfig, error)
}
2023-07-22 18:34:17 +00:00
type ConfigRegister struct {
2024-02-21 19:03:18 +00:00
configs map[string]AppConfig
2023-07-22 18:34:17 +00:00
}
2023-07-22 19:12:53 +00:00
type RegisteredConfig struct {
Name string
2024-02-21 19:03:18 +00:00
Config AppConfig
2023-07-22 19:12:53 +00:00
}
2023-07-22 18:34:17 +00:00
func NewConfigRegister() *ConfigRegister {
2024-02-21 19:03:18 +00:00
return &ConfigRegister{configs: map[string]AppConfig{}}
2023-07-22 18:34:17 +00:00
}
2024-02-21 19:03:18 +00:00
func (r *ConfigRegister) Register(name string, config AppConfig) {
2023-07-22 18:34:17 +00:00
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
}
2024-02-21 19:03:18 +00:00
func (r *ConfigRegister) GetConfig(name string) AppConfig {
2023-07-22 19:12:53 +00:00
return r.configs[name]
}