All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m36s
主要改动: - 改造 errors.New() 和 Wrap() 函数签名为可变参数,优先使用 errorMessages 映射表 - 添加 allErrorCodes 注册表和 init() 启动时校验,确保错误码与映射表一致 - 添加 TestAllCodesHaveMessages 和 TestNoOrphanMessages 测试防止映射表腐化 - 清理 109 处与映射表一致的冗余硬编码(service 层) - 保留业务特定消息覆盖能力 新增 API 用法: - errors.New(errors.CodeUnauthorized) // 使用映射表默认消息 - errors.New(errors.CodeNotFound, "提现申请不存在") // 覆盖为自定义消息
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
|
)
|
|
|
|
// BenchmarkGet 测试配置获取性能
|
|
func BenchmarkGet(b *testing.B) {
|
|
// 设置配置文件路径
|
|
_ = os.Setenv(constants.EnvConfigPath, "../../configs/config.yaml")
|
|
defer func() { _ = os.Unsetenv(constants.EnvConfigPath) }()
|
|
|
|
// 初始化配置
|
|
_, err := Load()
|
|
if err != nil {
|
|
b.Fatalf("加载配置失败: %v", err)
|
|
}
|
|
|
|
b.Run("GetServer", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = Get().Server
|
|
}
|
|
})
|
|
|
|
b.Run("GetRedis", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = Get().Redis
|
|
}
|
|
})
|
|
|
|
b.Run("GetLogging", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = Get().Logging
|
|
}
|
|
})
|
|
|
|
b.Run("GetMiddleware", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = Get().Middleware
|
|
}
|
|
})
|
|
|
|
b.Run("FullConfigAccess", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
cfg := Get()
|
|
_ = cfg.Server.Address
|
|
_ = cfg.Redis.Address
|
|
_ = cfg.Logging.Level
|
|
_ = cfg.Middleware.EnableRateLimiter
|
|
}
|
|
})
|
|
}
|