首次提交
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type RedisConfig struct {
|
||||
Host string
|
||||
Port int
|
||||
Password string
|
||||
Database int
|
||||
}
|
||||
|
||||
func loadRedis(env string) RedisConfig {
|
||||
if os.Getenv("REDIS_HOST") != "" {
|
||||
return redisFromEnv()
|
||||
}
|
||||
|
||||
switch env {
|
||||
case "production":
|
||||
return RedisConfig{
|
||||
Host: "172.31.38.162",
|
||||
Port: 16279,
|
||||
Password: getEnv("REDIS_PASSWORD", "eafon123!"),
|
||||
Database: 1,
|
||||
}
|
||||
default:
|
||||
return RedisConfig{
|
||||
Host: "ec2-3-69-138-29.eu-central-1.compute.amazonaws.com",
|
||||
Port: 16279,
|
||||
Password: getEnv("REDIS_PASSWORD", "eafon123!"),
|
||||
Database: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func redisFromEnv() RedisConfig {
|
||||
port, _ := strconv.Atoi(getEnv("REDIS_PORT", "16279"))
|
||||
db, _ := strconv.Atoi(getEnv("REDIS_DATABASE", "1"))
|
||||
|
||||
return RedisConfig{
|
||||
Host: os.Getenv("REDIS_HOST"),
|
||||
Port: port,
|
||||
Password: os.Getenv("REDIS_PASSWORD"),
|
||||
Database: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r RedisConfig) validate() error {
|
||||
if r.Host == "" {
|
||||
return fmt.Errorf("redis host is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user