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 {
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()
}
}