From 5ea681dbbe6a8b14aa4e65fde8f0f016c4f2b1e1 Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Mon, 27 Jul 2026 10:11:28 +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 | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 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..7008161 --- /dev/null +++ b/xy_sh/internal/config/config.go @@ -0,0 +1,35 @@ +package config + +import ( + "os" + "time" +) + +type Config struct { + ServerPort string + SM3Salt string + SM4Key string + ReadTimeout time.Duration + WriteTimeout time.Duration +} + +func LoadConfig() *Config { + port := getEnv("SERVER_PORT", "8080") + sm3Salt := getEnv("SM3_SALT", "default_salt_change_me") + sm4Key := getEnv("SM4_KEY", "default_key_16by") + + return &Config{ + ServerPort: port, + SM3Salt: sm3Salt, + SM4Key: sm4Key, + ReadTimeout: 30 * time.Second, + WriteTimeout: 30 * time.Second, + } +} + +func getEnv(key, defaultValue string) string { + if value := os.Getenv(key); value != "" { + return value + } + return defaultValue +} \ No newline at end of file