1
1
/*
2
- * @Author: lwnmengjing
3
- * @Date: 2021/6/10 3:39 下午
4
- * @Last Modified by: lwnmengjing
5
- * @Last Modified time: 2021/6/10 3:39 下午
2
+ * @Author: zhangwenjian
3
+ * @Date: 2025/04/13 22:03
4
+ * @Last Modified by: zhangwenjian
5
+ * @Last Modified time: 2025/04/13 22:03
6
6
*/
7
7
8
8
package storage
@@ -17,27 +17,34 @@ import (
17
17
18
18
// Setup 配置storage组件
19
19
func Setup () {
20
- //4. 设置缓存
20
+ setupCache ()
21
+ setupCaptcha ()
22
+ setupQueue ()
23
+ }
24
+
25
+ func setupCache () {
21
26
cacheAdapter , err := config .CacheConfig .Setup ()
22
27
if err != nil {
23
28
log .Fatalf ("cache setup error, %s\n " , err .Error ())
24
29
}
25
30
sdk .Runtime .SetCacheAdapter (cacheAdapter )
26
- //5. 设置验证码store
27
- captcha .SetStore (captcha .NewCacheStore (cacheAdapter , 600 ))
31
+ }
32
+
33
+ func setupCaptcha () {
34
+ captcha .SetStore (captcha .NewCacheStore (sdk .Runtime .GetCacheAdapter (), 600 ))
35
+ }
28
36
29
- //6. 设置队列
30
- if ! config .QueueConfig .Empty () {
31
- if q := sdk .Runtime .GetQueueAdapter (); q != nil {
32
- q .Shutdown ()
33
- }
34
- queueAdapter , err := config .QueueConfig .Setup ()
35
- if err != nil {
36
- log .Fatalf ("queue setup error, %s\n " , err .Error ())
37
- }
38
- sdk .Runtime .SetQueueAdapter (queueAdapter )
39
- defer func () {
40
- go queueAdapter .Run ()
41
- }()
37
+ func setupQueue () {
38
+ if config .QueueConfig .Empty () {
39
+ return
40
+ }
41
+ if q := sdk .Runtime .GetQueueAdapter (); q != nil {
42
+ q .Shutdown ()
43
+ }
44
+ queueAdapter , err := config .QueueConfig .Setup ()
45
+ if err != nil {
46
+ log .Fatalf ("queue setup error, %s\n " , err .Error ())
42
47
}
48
+ sdk .Runtime .SetQueueAdapter (queueAdapter )
49
+ go queueAdapter .Run ()
43
50
}
0 commit comments