back to int

This commit is contained in:
Nixon 2024-08-13 14:46:21 -07:00
parent c3e5e5d8da
commit a4ff4b238f
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 string `json:"db"` DB int `json:"db"`
client *redis.Client client *redis.Client
} }
@ -32,17 +32,13 @@ 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 h.DB < 0 || h.DB > 15 {
if err != nil { return fmt.Errorf("invalid db value: %d", h.DB)
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: db, DB: h.DB, // Directly use h.DB
}) })
return nil return nil
} }
@ -83,9 +79,15 @@ func (h *KeyDBHandler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return d.ArgErr() return d.ArgErr()
} }
case "db": case "db":
if !d.Args(&h.DB) { var dbString string
if !d.Args(&dbString) {
return d.ArgErr() return d.ArgErr()
} }
db, err := strconv.Atoi(dbString)
if err != nil {
return err
}
h.DB = db
} }
} }
} }