try to fix int / str error

This commit is contained in:
Nixon 2024-08-13 14:10:39 -07:00
parent de880bf082
commit 6331c931e1
No known key found for this signature in database

View file

@ -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)
)