32 lines
540 B
Go
32 lines
540 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
type RedisConfig struct {
|
|
Host string
|
|
Port int
|
|
Password string
|
|
Database int
|
|
}
|
|
|
|
func loadRedis() RedisConfig {
|
|
port, _ := strconv.Atoi(getEnv("REDIS_PORT", "6379"))
|
|
db, _ := strconv.Atoi(getEnv("REDIS_DATABASE", "1"))
|
|
return RedisConfig{
|
|
Host: getEnv("REDIS_HOST", ""),
|
|
Port: port,
|
|
Password: getEnv("REDIS_PASSWORD", ""),
|
|
Database: db,
|
|
}
|
|
}
|
|
|
|
func (r RedisConfig) validate() error {
|
|
if r.Host == "" {
|
|
return fmt.Errorf("redis host is required")
|
|
}
|
|
return nil
|
|
}
|