fix(config): 补充支持无后缀 .yaml 配置文件加载并升级 file 依赖至 v1.0.7 (by AI)
This commit is contained in:
parent
be37a3868f
commit
fd2ac6079b
@ -1,5 +1,13 @@
|
||||
# 更新日志 (Changelog)
|
||||
|
||||
## [1.0.7] - 2026-05-09
|
||||
- **修复**: 在 `resolveConfigPath` 中补充了对无后缀 `.yaml` 配置文件的支持。
|
||||
- **变更**: 将 `apigo.cc/go/file` 的依赖升级至 `v1.0.7` 以对齐基础设施。
|
||||
- **变更**: 补充针对无后缀 `.yaml` 文件的回归测试 `TestForYaml_Support`。
|
||||
|
||||
## [1.0.6] - 2026-05-06
|
||||
- **变更**: 修复与基础设施的兼容性。
|
||||
|
||||
## [1.0.5] - 2026-05-05
|
||||
- **变更**: 基础设施对齐与生态系统同步发布。
|
||||
|
||||
|
||||
5
TEST.md
5
TEST.md
@ -10,6 +10,7 @@
|
||||
- `TestForMap_Regression`: 验证基础的基于 Map 的配置加载。
|
||||
- `TestForStruct_Regression`: 验证基于结构体的映射及环境变量覆盖。
|
||||
- `TestForYml_Regression`: 检查 YAML 配置解析,包括接口切片和映射。
|
||||
- `TestForYaml_Support`: 验证针对无后缀 `.yaml` 文件的默认解析支持。
|
||||
|
||||
## 基准测试结果
|
||||
|
||||
@ -17,8 +18,8 @@
|
||||
goos: darwin
|
||||
goarch: amd64
|
||||
pkg: apigo.cc/go/config
|
||||
BenchmarkLoad-16 9104 123326 ns/op 5136 B/op 104 allocs/op
|
||||
BenchmarkApplyEnvOverrides-16 260586 4700 ns/op 2657 B/op 64 allocs/op
|
||||
BenchmarkLoad-16 6255 164111 ns/op
|
||||
BenchmarkApplyEnvOverrides-16 294292 3592 ns/op
|
||||
```
|
||||
|
||||
*注:基准测试反映了在 Intel i9-9980HK 上的性能表现。*
|
||||
|
||||
@ -89,10 +89,13 @@ func resolveConfigPath(name string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Otherwise, check for .yml then .json
|
||||
// Otherwise, check for .yml, .yaml, then .json
|
||||
if file.Exists(name + ".yml") {
|
||||
return name + ".yml"
|
||||
}
|
||||
if file.Exists(name + ".yaml") {
|
||||
return name + ".yaml"
|
||||
}
|
||||
if file.Exists(name + ".json") {
|
||||
return name + ".json"
|
||||
}
|
||||
|
||||
4
go.mod
4
go.mod
@ -3,8 +3,8 @@ module apigo.cc/go/config
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
apigo.cc/go/cast v1.2.7
|
||||
apigo.cc/go/file v1.0.6
|
||||
apigo.cc/go/cast v1.2.8
|
||||
apigo.cc/go/file v1.0.7
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
30
yaml_test.go
Normal file
30
yaml_test.go
Normal file
@ -0,0 +1,30 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"apigo.cc/go/config"
|
||||
)
|
||||
|
||||
func TestForYaml_Support(t *testing.T) {
|
||||
os.Clearenv()
|
||||
// create a test.yaml without extension in the load call
|
||||
os.WriteFile("test3.yaml", []byte(`
|
||||
name: yaml-config
|
||||
sets: [4, 5, 6]
|
||||
`), 0644)
|
||||
defer os.Remove("test3.yaml")
|
||||
|
||||
var testConf RegressionConf
|
||||
if err := config.Load(&testConf, "test3"); err != nil {
|
||||
t.Errorf("Load failed: %v", err)
|
||||
}
|
||||
|
||||
if testConf.Name != "yaml-config" {
|
||||
t.Errorf("Expected name yaml-config, got %v", testConf.Name)
|
||||
}
|
||||
if len(testConf.Sets) != 3 || testConf.Sets[0] != 4 {
|
||||
t.Errorf("Sets failed: %v", testConf.Sets)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user