From d41f7c30c7debcf8d85cee2594c7fcccc086f6ba Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Fri, 24 Jul 2026 18:13:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6:=20xy=5Fsh?= =?UTF-8?q?/internal/config/config.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xy_sh/internal/config/config.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 xy_sh/internal/config/config.go 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