publish v1.5.1

This commit is contained in:
AI Engineer 2026-06-04 13:33:54 +08:00
parent b02524777c
commit 0732f2e03f
3 changed files with 40 additions and 1 deletions

View File

@ -1,5 +1,12 @@
# 更新日志 (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` 以对齐基础设施。

View File

@ -60,7 +60,11 @@ 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)
} }

View File

@ -60,3 +60,31 @@ 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)
}
}