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