2021-08-20 14:59:13 +08:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
AliSmsConfig aliSmsConfig
|
|
|
|
RedisConfig redisConfig
|
2021-08-20 15:15:05 +08:00
|
|
|
MySQLConfig mysqlConfig
|
2021-08-20 14:59:13 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// 从环境变量获取字符串类型值
|
|
|
|
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
|
|
|
|
}
|