Compare commits
No commits in common. "main" and "v1.5.0" have entirely different histories.
@ -1,12 +1,5 @@
|
|||||||
# 更新日志 (Changelog)
|
# 更新日志 (Changelog)
|
||||||
|
|
||||||
## [1.5.1] - 2026-06-04
|
|
||||||
- **修复**: 优化 `config.Load` 加载逻辑,支持在 `env.yaml` 中通过 `name` 作为 key 查找并加载特定配置块(如 `service:`)。
|
|
||||||
- **变更**: 补充 `TestConfig_EnvYamlWithPrefix` 测试用例验证前缀加载功能。
|
|
||||||
|
|
||||||
## [1.5.0] - 2026-05-10
|
|
||||||
- **变更**: 基础设施全局对齐发布。
|
|
||||||
|
|
||||||
## [1.0.7] - 2026-05-09
|
## [1.0.7] - 2026-05-09
|
||||||
- **修复**: 在 `resolveConfigPath` 中补充了对无后缀 `.yaml` 配置文件的支持。
|
- **修复**: 在 `resolveConfigPath` 中补充了对无后缀 `.yaml` 配置文件的支持。
|
||||||
- **变更**: 将 `apigo.cc/go/file` 的依赖升级至 `v1.0.7` 以对齐基础设施。
|
- **变更**: 将 `apigo.cc/go/file` 的依赖升级至 `v1.0.7` 以对齐基础设施。
|
||||||
|
|||||||
@ -60,11 +60,7 @@ func Load(conf interface{}, name string) error {
|
|||||||
if envFile != "" {
|
if envFile != "" {
|
||||||
envConf := map[string]interface{}{}
|
envConf := map[string]interface{}{}
|
||||||
if err := file.UnmarshalFile(envFile, &envConf); err == nil {
|
if err := file.UnmarshalFile(envFile, &envConf); err == nil {
|
||||||
if val, ok := envConf[name]; ok {
|
|
||||||
cast.Convert(conf, val)
|
|
||||||
} else {
|
|
||||||
cast.Convert(conf, envConf)
|
cast.Convert(conf, envConf)
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,31 +60,3 @@ func TestConfig_ComplexStruct(t *testing.T) {
|
|||||||
t.Errorf("Duration failed, got %v", conf.Duration.TimeDuration())
|
t.Errorf("Duration failed, got %v", conf.Duration.TimeDuration())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfig_EnvYamlWithPrefix(t *testing.T) {
|
|
||||||
os.Clearenv()
|
|
||||||
// Create env.yaml with a prefixed block
|
|
||||||
os.WriteFile("env.yaml", []byte(`
|
|
||||||
service:
|
|
||||||
app: "emp"
|
|
||||||
listen: ":3000"
|
|
||||||
`), 0644)
|
|
||||||
defer os.Remove("env.yaml")
|
|
||||||
|
|
||||||
type ServiceConfig struct {
|
|
||||||
App string
|
|
||||||
Listen string
|
|
||||||
}
|
|
||||||
|
|
||||||
var conf ServiceConfig
|
|
||||||
if err := config.Load(&conf, "service"); err != nil {
|
|
||||||
t.Errorf("Load failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if conf.App != "emp" {
|
|
||||||
t.Errorf("App mismatch: expected emp, got %s", conf.App)
|
|
||||||
}
|
|
||||||
if conf.Listen != ":3000" {
|
|
||||||
t.Errorf("Listen mismatch: expected :3000, got %s", conf.Listen)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user