添加文件: xy_sh/internal/config/config.go

This commit is contained in:
renzhiyuan 2026-07-24 18:13:52 +08:00
parent 925dfb6235
commit d41f7c30c7
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package config
import "os"
// Config 应用配置
type Config struct {
ServerPort string // 服务监听端口
SM4Key []byte // SM4 加密密钥16字节
SM3Salt []byte // SM3 签名盐值
}
// LoadConfig 加载配置(从环境变量读取,生产环境建议使用配置文件或配置中心)
func LoadConfig() *Config {
return &Config{
ServerPort: getEnv("SERVER_PORT", "8080"),
SM4Key: []byte(getEnv("SM4_KEY", "1234567890123456")), // 默认16字节测试密钥
SM3Salt: []byte(getEnv("SM3_SALT", "default_sm3_salt")),
}
}
func getEnv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}