添加文件: xy_sh/internal/config/config.go
This commit is contained in:
parent
8aee4d67ea
commit
1722b01f1c
|
|
@ -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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue