数据库+redis+meilisearch+s3+EQURL 配置全部走环境变量,不在代码层硬编码
This commit is contained in:
@@ -2,7 +2,6 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -13,38 +12,13 @@ type RedisConfig struct {
|
||||
Database int
|
||||
}
|
||||
|
||||
func loadRedis(env string) RedisConfig {
|
||||
switch env {
|
||||
case "production":
|
||||
if os.Getenv("REDIS_HOST") != "" {
|
||||
return redisFromEnv("16279")
|
||||
}
|
||||
return RedisConfig{
|
||||
Host: "172.31.38.162",
|
||||
Port: 16279,
|
||||
Password: getEnv("REDIS_PASSWORD", "eafon123!"),
|
||||
Database: 1,
|
||||
}
|
||||
default:
|
||||
port, _ := strconv.Atoi(getEnv("REDIS_PORT", "6379"))
|
||||
db, _ := strconv.Atoi(getEnv("REDIS_DATABASE", "1"))
|
||||
return RedisConfig{
|
||||
Host: getEnv("REDIS_HOST", "192.168.9.127"),
|
||||
Port: port,
|
||||
Password: getEnv("REDIS_PASSWORD", ""),
|
||||
Database: db,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func redisFromEnv(defaultPort string) RedisConfig {
|
||||
port, _ := strconv.Atoi(getEnv("REDIS_PORT", defaultPort))
|
||||
func loadRedis() RedisConfig {
|
||||
port, _ := strconv.Atoi(getEnv("REDIS_PORT", "6379"))
|
||||
db, _ := strconv.Atoi(getEnv("REDIS_DATABASE", "1"))
|
||||
|
||||
return RedisConfig{
|
||||
Host: os.Getenv("REDIS_HOST"),
|
||||
Host: getEnv("REDIS_HOST", ""),
|
||||
Port: port,
|
||||
Password: os.Getenv("REDIS_PASSWORD"),
|
||||
Password: getEnv("REDIS_PASSWORD", ""),
|
||||
Database: db,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user