35 lines
651 B
Go
35 lines
651 B
Go
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
|
|
} |