diff --git a/src/config.go b/src/config.go index 2482483..f656dfb 100644 --- a/src/config.go +++ b/src/config.go @@ -16,16 +16,18 @@ type RouteConfig struct { MaxScale int `yaml:"max_scale"` } +type RedisConfig struct { + Host string `yaml:"host"` + Port uint16 `yaml:"port"` + User string `yaml:"user"` + Password string `yaml:"password"` + Database int `yaml:"database"` +} + type Configuration struct { - Host string `yaml:"host"` - Port uint16 `yaml:"port"` - Redis struct { - Host string `yaml:"host"` - Port uint16 `yaml:"port"` - User string `yaml:"user"` - Password string `yaml:"password"` - Database int `yaml:"database"` - } `yaml:"redis"` + Host string `yaml:"host"` + Port uint16 `yaml:"port"` + Redis RedisConfig `yaml:"redis"` Routes struct { Face RouteConfig `yaml:"face"` Head RouteConfig `yaml:"head"` diff --git a/src/main.go b/src/main.go index 4c91d8b..6ace398 100644 --- a/src/main.go +++ b/src/main.go @@ -33,7 +33,7 @@ func init() { log.Fatal(err) } - if err = r.Connect(config.Redis.URI, config.Redis.Database); err != nil { + if err = r.Connect(config.Redis); err != nil { log.Fatal(err) } diff --git a/src/redis.go b/src/redis.go index 1516bfc..b47cebb 100644 --- a/src/redis.go +++ b/src/redis.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "fmt" "image" "image/draw" "time" @@ -14,10 +15,12 @@ type Redis struct { conn *redis.Client } -func (r *Redis) Connect(uri string, database int) error { +func (r *Redis) Connect(conf RedisConfig) error { c := redis.NewClient(&redis.Options{ - Addr: uri, - DB: database, + Addr: fmt.Sprintf("%s:%d", conf.Host, conf.Port), + Username: conf.User, + Password: conf.Password, + DB: conf.Database, }) r.conn = c