diff --git a/xy_sh/internal/config/config.go b/xy_sh/internal/config/config.go new file mode 100644 index 0000000..6e05fb6 --- /dev/null +++ b/xy_sh/internal/config/config.go @@ -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 +} \ No newline at end of file