From 1722b01f1cafd867bce52fa48724447017015c10 Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Thu, 23 Jul 2026 18:42:13 +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 | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 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..c91adc4 --- /dev/null +++ b/xy_sh/internal/config/config.go @@ -0,0 +1,36 @@ +package config + +import ( + "os" + "time" +) + +// Config 应用配置 +type Config struct { + ServerPort string + ReadTimeout time.Duration + WriteTimeout time.Duration + SM3Salt string + SM4Key []byte + CallbackURL string +} + +// Load 加载配置,优先从环境变量读取 +func Load() *Config { + sm4KeyStr := getEnv("SM4_KEY", "1234567890abcdef") + return &Config{ + ServerPort: getEnv("SERVER_PORT", "8080"), + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + SM3Salt: getEnv("SM3_SALT", "default_salt"), + SM4Key: []byte(sm4KeyStr), + CallbackURL: getEnv("CALLBACK_URL", ""), + } +} + +func getEnv(key, defaultValue string) string { + if v := os.Getenv(key); v != "" { + return v + } + return defaultValue +} \ No newline at end of file