From 6331c931e1bdaa7b680ae8df593693dd9acaeac2 Mon Sep 17 00:00:00 2001 From: Nixon Date: Tue, 13 Aug 2024 14:10:39 -0700 Subject: [PATCH] try to fix int / str error --- keydb_extension.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/keydb_extension.go b/keydb_extension.go index 637d58c..3c31e46 100644 --- a/keydb_extension.go +++ b/keydb_extension.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "strconv" "time" "github.com/caddyserver/caddy/v2" @@ -19,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 } @@ -31,10 +32,14 @@ func (KeyDBHandler) CaddyModule() caddy.ModuleInfo { } func (h *KeyDBHandler) Provision(ctx caddy.Context) error { + db, err := strconv.Atoi(h.DB) + if err != nil { + return fmt.Errorf("invalid db value: %v", err) + } h.client = redis.NewClient(&redis.Options{ Addr: h.Address, Password: h.Password, - DB: h.DB, + DB: db, }) return nil } @@ -89,4 +94,3 @@ var ( _ caddyhttp.MiddlewareHandler = (*KeyDBHandler)(nil) _ caddyfile.Unmarshaler = (*KeyDBHandler)(nil) ) -