This commit is contained in:
Nixon 2024-08-13 14:34:12 -07:00
parent b41b96fb69
commit c3e5e5d8da
No known key found for this signature in database

View file

@ -20,7 +20,7 @@ func init() {
type KeyDBHandler struct { type KeyDBHandler struct {
Address string `json:"address"` Address string `json:"address"`
Password string `json:"password"` Password string `json:"password"`
DB int `json:"db"` DB string `json:"db"`
client *redis.Client client *redis.Client
} }
@ -32,10 +32,17 @@ func (KeyDBHandler) CaddyModule() caddy.ModuleInfo {
} }
func (h *KeyDBHandler) Provision(ctx caddy.Context) error { 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{ h.client = redis.NewClient(&redis.Options{
Addr: h.Address, Addr: h.Address,
Password: h.Password, Password: h.Password,
DB: h.DB, DB: db,
}) })
return nil return nil
} }
@ -76,7 +83,7 @@ func (h *KeyDBHandler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return d.ArgErr() return d.ArgErr()
} }
case "db": case "db":
if !d.Args(strconv.Itoa(h.DB)) { if !d.Args(&h.DB) {
return d.ArgErr() return d.ArgErr()
} }
} }