diff --git a/config/cluster.go b/config/cluster.go index 3e590c6..8b8455f 100644 --- a/config/cluster.go +++ b/config/cluster.go @@ -1,7 +1,6 @@ package config import ( - "errors" "reflect" "github.com/mitchellh/mapstructure" @@ -13,19 +12,6 @@ type ClusterConfig struct { Etcd *EtcdConfig `mapstructure:"etcd"` } -type RedisConfig struct { - Address string `mapstructure:"address"` - Password string `mapstructure:"password"` - DB int `mapstructure:"db"` -} - -func (r *RedisConfig) Validate() error { - if r.Address == "" { - return errors.New("address is required") - } - return nil -} - func clusterConfigHook() mapstructure.DecodeHookFuncType { return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) { if f.Kind() != reflect.Map || t != reflect.TypeOf(&ClusterConfig{}) { diff --git a/config/redis.go b/config/redis.go new file mode 100644 index 0000000..2531aef --- /dev/null +++ b/config/redis.go @@ -0,0 +1,26 @@ +package config + +import "errors" + +var _ Validator = (*RedisConfig)(nil) +var _ Defaults = (*RedisConfig)(nil) + +type RedisConfig struct { + Address string `mapstructure:"address"` + Password string `mapstructure:"password"` + DB int `mapstructure:"db"` +} + +func (r *RedisConfig) Defaults() map[string]interface{} { + return map[string]interface{}{ + "address": "localhost:6379", + "db": 0, + } +} + +func (r *RedisConfig) Validate() error { + if r.Address == "" { + return errors.New("address is required") + } + return nil +}