Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base.go 714B

123456789101112131415161718192021222324252627282930
  1. package subconfigs
  2. import (
  3. "gopkg.in/yaml.v2"
  4. )
  5. // BaseConfig 基础配置(所有子配置继承)
  6. type BaseConfig struct{}
  7. // LoadFromYAML 从YAML数据加载
  8. func (b *BaseConfig) LoadFromYAML(data map[string]interface{}, target interface{}) error {
  9. // 转换为yaml字节
  10. yamlBytes, err := yaml.Marshal(data)
  11. if err != nil {
  12. return err
  13. }
  14. // 解析到目标结构体
  15. return yaml.Unmarshal(yamlBytes, target)
  16. }
  17. // GetRegisteredConfig 获取注册的配置实例(避免名称冲突)
  18. func GetRegisteredConfig(name string) ConfigLoader {
  19. return registry[name]
  20. }
  21. // GetAllRegisteredConfigs 获取所有注册的配置
  22. func GetAllRegisteredConfigs() map[string]ConfigLoader {
  23. return registry
  24. }