Skip to content

Commit e5f084c

Browse files
author
蒋吉兆
committed
修复 v8下redis 验证码模式 存在的未传入context的bug
(cherry picked from commit 2342a47)
1 parent 0df39ff commit e5f084c

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

server/go.mod

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,56 @@ module github.com/flipped-aurora/gin-vue-admin/server
33
go 1.16
44

55
require (
6+
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
67
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
78
github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible
9+
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
810
github.com/casbin/casbin/v2 v2.11.0
911
github.com/casbin/gorm-adapter/v3 v3.0.2
1012
github.com/dgrijalva/jwt-go v3.2.0+incompatible
11-
github.com/flipped-aurora/gva-plug-email v0.0.0-20210823152517-a061eeea2d16
13+
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
1214
github.com/fsnotify/fsnotify v1.4.9
1315
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
1416
github.com/gin-gonic/gin v1.6.3
17+
github.com/go-ole/go-ole v1.2.4 // indirect
18+
github.com/go-openapi/jsonreference v0.19.6 // indirect
19+
github.com/go-openapi/spec v0.20.3 // indirect
20+
github.com/go-openapi/swag v0.19.15 // indirect
21+
github.com/go-playground/validator/v10 v10.3.0 // indirect
1522
github.com/go-redis/redis/v8 v8.11.0
1623
github.com/go-sql-driver/mysql v1.5.0
1724
github.com/gookit/color v1.3.1
25+
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
1826
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
27+
github.com/json-iterator/go v1.1.10 // indirect
1928
github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible
29+
github.com/lestrrat-go/strftime v1.0.3 // indirect
30+
github.com/mailru/easyjson v0.7.7 // indirect
31+
github.com/mitchellh/mapstructure v1.2.2 // indirect
2032
github.com/mojocn/base64Captcha v1.3.1
33+
github.com/pelletier/go-toml v1.6.0 // indirect
34+
github.com/pkg/errors v0.9.1 // indirect
2135
github.com/qiniu/api.v7/v7 v7.4.1
2236
github.com/robfig/cron/v3 v3.0.1
2337
github.com/satori/go.uuid v1.2.0
2438
github.com/shirou/gopsutil v3.21.1+incompatible
39+
github.com/spf13/afero v1.2.2 // indirect
40+
github.com/spf13/cast v1.3.1 // indirect
41+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
42+
github.com/spf13/pflag v1.0.5 // indirect
2543
github.com/spf13/viper v1.7.0
2644
github.com/swaggo/gin-swagger v1.3.0
2745
github.com/swaggo/swag v1.7.0
46+
github.com/tebeka/strftime v0.1.3 // indirect
2847
github.com/tencentyun/cos-go-sdk-v5 v0.7.19
2948
github.com/unrolled/secure v1.0.7
3049
github.com/xuri/excelize/v2 v2.4.1
3150
go.uber.org/zap v1.10.0
3251
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
52+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
53+
golang.org/x/tools v0.1.5 // indirect
54+
google.golang.org/protobuf v1.24.0 // indirect
55+
gopkg.in/ini.v1 v1.55.0 // indirect
3356
gorm.io/driver/mysql v1.0.1
3457
gorm.io/gorm v1.20.7
3558
)

server/utils/captcha/redis.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package captcha
22

33
import (
4-
"time"
5-
4+
"context"
65
"github.com/flipped-aurora/gin-vue-admin/server/global"
7-
86
"github.com/mojocn/base64Captcha"
97
"go.uber.org/zap"
8+
"time"
109
)
1110

12-
func NewDefaultRedisStore() base64Captcha.Store {
11+
func NewDefaultRedisStore() *RedisStore {
1312
return &RedisStore{
1413
Expiration: time.Second * 180,
1514
PreKey: "CAPTCHA_",
@@ -19,23 +18,29 @@ func NewDefaultRedisStore() base64Captcha.Store {
1918
type RedisStore struct {
2019
Expiration time.Duration
2120
PreKey string
21+
Context context.Context
22+
}
23+
24+
func (rs *RedisStore) UseWithCtx(ctx context.Context) base64Captcha.Store {
25+
rs.Context = ctx
26+
return rs
2227
}
2328

2429
func (rs *RedisStore) Set(id string, value string) {
25-
err := global.GVA_REDIS.Set(rs.PreKey+id, value, rs.Expiration).Err()
30+
err := global.GVA_REDIS.Set(rs.Context, rs.PreKey+id, value, rs.Expiration).Err()
2631
if err != nil {
2732
global.GVA_LOG.Error("RedisStoreSetError!", zap.Error(err))
2833
}
2934
}
3035

3136
func (rs *RedisStore) Get(key string, clear bool) string {
32-
val, err := global.GVA_REDIS.Get(key).Result()
37+
val, err := global.GVA_REDIS.Get(rs.Context, key).Result()
3338
if err != nil {
3439
global.GVA_LOG.Error("RedisStoreGetError!", zap.Error(err))
3540
return ""
3641
}
3742
if clear {
38-
err := global.GVA_REDIS.Del(key).Err()
43+
err := global.GVA_REDIS.Del(rs.Context, key).Err()
3944
if err != nil {
4045
global.GVA_LOG.Error("RedisStoreClearError!", zap.Error(err))
4146
return ""

0 commit comments

Comments
 (0)