xy_sh-20260724181350/xy_sh/internal/config/config.go

26 lines
676 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}