From eed2c1ccf5ae0ab0e0032859abe01bf9ec9a1765 Mon Sep 17 00:00:00 2001 From: xmdhs Date: Wed, 11 Oct 2023 23:26:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20redis=20=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/cache/redis.go | 4 ++++ model/model.go | 6 +++--- service/captcha.go | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/db/cache/redis.go b/db/cache/redis.go index 57b022c..de3261f 100644 --- a/db/cache/redis.go +++ b/db/cache/redis.go @@ -4,6 +4,7 @@ package cache import ( "context" + "errors" "fmt" "time" @@ -35,6 +36,9 @@ func (r *RedisCache) Del(k []byte) error { func (r *RedisCache) Get(k []byte) ([]byte, error) { value, err := r.c.Get(context.Background(), string(k)).Bytes() if err != nil { + if errors.Is(err, redis.Nil) { + return nil, nil + } return nil, fmt.Errorf("RedisCache.Get: %w", err) } return value, nil diff --git a/model/model.go b/model/model.go index ec6f5b3..3c94a65 100644 --- a/model/model.go +++ b/model/model.go @@ -31,9 +31,8 @@ type TokenClaims struct { } type Captcha struct { - Type string `json:"type"` - SiteKey string `json:"siteKey"` - ServerName string `json:"serverName"` + Type string `json:"type"` + SiteKey string `json:"siteKey"` } type UserInfo struct { @@ -62,6 +61,7 @@ type ChangeName struct { type Config struct { Captcha Captcha `json:"captcha"` AllowChangeName bool + ServerName string `json:"serverName"` } type EditUser struct { diff --git a/service/captcha.go b/service/captcha.go index f0700ec..8540d47 100644 --- a/service/captcha.go +++ b/service/captcha.go @@ -15,10 +15,10 @@ import ( func (w *WebService) GetConfig(ctx context.Context) model.Config { return model.Config{ Captcha: model.Captcha{ - Type: w.config.Captcha.Type, - SiteKey: w.config.Captcha.SiteKey, - ServerName: w.config.ServerName, + Type: w.config.Captcha.Type, + SiteKey: w.config.Captcha.SiteKey, }, + ServerName: w.config.ServerName, AllowChangeName: !w.config.OfflineUUID, } }