47 lines
795 B
Go
47 lines
795 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
var (
|
|
AliSmsConfig aliSmsConfig
|
|
RedisConfig redisConfig
|
|
)
|
|
|
|
// 从环境变量获取字符串类型值
|
|
func getEnvVal(key, defaultVal string) string {
|
|
val, exist := os.LookupEnv(key)
|
|
if !exist {
|
|
return defaultVal
|
|
}
|
|
return val
|
|
}
|
|
|
|
// 从环境变量获取数字类型值
|
|
func getEnvIntVal(key string, defaultVal int) int {
|
|
valStr, exist := os.LookupEnv(key)
|
|
if !exist {
|
|
return defaultVal
|
|
}
|
|
val, err := strconv.Atoi(valStr)
|
|
if err != nil {
|
|
return defaultVal
|
|
}
|
|
return val
|
|
}
|
|
|
|
// 从环境变量获取数字类型值
|
|
func getEnvBoolVal(key string, defaultVal bool) bool {
|
|
valStr, exist := os.LookupEnv(key)
|
|
if !exist {
|
|
return defaultVal
|
|
}
|
|
val, err := strconv.ParseBool(valStr)
|
|
if err != nil {
|
|
return defaultVal
|
|
}
|
|
return val
|
|
}
|