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"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2"
|
"github.com/caddyserver/caddy/v2"
|
||||||
|
@ -19,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 int `json:"db"`
|
DB string `json:"db"`
|
||||||
client *redis.Client
|
client *redis.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,10 +32,14 @@ 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 err != nil {
|
||||||
|
return fmt.Errorf("invalid db value: %v", err)
|
||||||
|
}
|
||||||
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: h.DB,
|
DB: db,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -89,4 +94,3 @@ var (
|
||||||
_ caddyhttp.MiddlewareHandler = (*KeyDBHandler)(nil)
|
_ caddyhttp.MiddlewareHandler = (*KeyDBHandler)(nil)
|
||||||
_ caddyfile.Unmarshaler = (*KeyDBHandler)(nil)
|
_ caddyfile.Unmarshaler = (*KeyDBHandler)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue