11/*
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
66 */
77
88package storage
@@ -17,27 +17,34 @@ import (
1717
1818// Setup 配置storage组件
1919func Setup () {
20- //4. 设置缓存
20+ setupCache ()
21+ setupCaptcha ()
22+ setupQueue ()
23+ }
24+
25+ func setupCache () {
2126 cacheAdapter , err := config .CacheConfig .Setup ()
2227 if err != nil {
2328 log .Fatalf ("cache setup error, %s\n " , err .Error ())
2429 }
2530 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+ }
2836
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 ())
4247 }
48+ sdk .Runtime .SetQueueAdapter (queueAdapter )
49+ go queueAdapter .Run ()
4350}
0 commit comments