From 762eba5af73001295ea66fbfc5d33acdbffb1e8f Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Sun, 13 Apr 2025 22:04:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor=F0=9F=8E=A8:=20=E9=87=8D=E6=9E=84=20Se?= =?UTF-8?q?tup=20=E5=87=BD=E6=95=B0=EF=BC=8C=E6=8B=86=E5=88=86=E4=B8=BA?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E5=AD=90=E5=87=BD=E6=95=B0=E4=BB=A5=E6=8F=90?= =?UTF-8?q?=E9=AB=98=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/storage/initialize.go | 47 +++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/common/storage/initialize.go b/common/storage/initialize.go index 0617af84..f1e6933c 100644 --- a/common/storage/initialize.go +++ b/common/storage/initialize.go @@ -1,8 +1,8 @@ /* - * @Author: lwnmengjing - * @Date: 2021/6/10 3:39 下午 - * @Last Modified by: lwnmengjing - * @Last Modified time: 2021/6/10 3:39 下午 + * @Author: zhangwenjian + * @Date: 2025/04/13 22:03 + * @Last Modified by: zhangwenjian + * @Last Modified time: 2025/04/13 22:03 */ package storage @@ -17,27 +17,34 @@ import ( // Setup 配置storage组件 func Setup() { - //4. 设置缓存 + setupCache() + setupCaptcha() + setupQueue() +} + +func setupCache() { cacheAdapter, err := config.CacheConfig.Setup() if err != nil { log.Fatalf("cache setup error, %s\n", err.Error()) } sdk.Runtime.SetCacheAdapter(cacheAdapter) - //5. 设置验证码store - captcha.SetStore(captcha.NewCacheStore(cacheAdapter, 600)) +} - //6. 设置队列 - if !config.QueueConfig.Empty() { - if q := sdk.Runtime.GetQueueAdapter(); q != nil { - q.Shutdown() - } - queueAdapter, err := config.QueueConfig.Setup() - if err != nil { - log.Fatalf("queue setup error, %s\n", err.Error()) - } - sdk.Runtime.SetQueueAdapter(queueAdapter) - defer func() { - go queueAdapter.Run() - }() +func setupCaptcha() { + captcha.SetStore(captcha.NewCacheStore(sdk.Runtime.GetCacheAdapter(), 600)) +} + +func setupQueue() { + if config.QueueConfig.Empty() { + return + } + if q := sdk.Runtime.GetQueueAdapter(); q != nil { + q.Shutdown() + } + queueAdapter, err := config.QueueConfig.Setup() + if err != nil { + log.Fatalf("queue setup error, %s\n", err.Error()) } + sdk.Runtime.SetQueueAdapter(queueAdapter) + go queueAdapter.Run() }