From c3e5e5d8da84e2271e8f58da6c2e44d99ea76def Mon Sep 17 00:00:00 2001 From: Nixon Date: Tue, 13 Aug 2024 14:34:12 -0700 Subject: [PATCH] ints --- keydb_extension.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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() } }