try to fix int / str error
This commit is contained in:
parent
de880bf082
commit
6331c931e1
1 changed files with 7 additions and 3 deletions
|
@ -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)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue