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