diff --git a/keydb_extension.go b/keydb_extension.go index 63463f2..c4afcb2 100644 --- a/keydb_extension.go +++ b/keydb_extension.go @@ -20,7 +20,7 @@ func init() { type KeyDBHandler struct { Address string `json:"address"` Password string `json:"password"` - DB int `json:"db"` + DB string `json:"db"` client *redis.Client } @@ -32,10 +32,17 @@ func (KeyDBHandler) CaddyModule() caddy.ModuleInfo { } func (h *KeyDBHandler) Provision(ctx caddy.Context) error { + db, err := strconv.Atoi(h.DB) + if err != nil { + return err + } + if db < 0 || db > 15 { + return fmt.Errorf("invalid db value: %d", db) + } h.client = redis.NewClient(&redis.Options{ Addr: h.Address, Password: h.Password, - DB: h.DB, + DB: db, }) return nil } @@ -76,7 +83,7 @@ func (h *KeyDBHandler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { return d.ArgErr() } case "db": - if !d.Args(strconv.Itoa(h.DB)) { + if !d.Args(&h.DB) { return d.ArgErr() } }