From ccaf64bbfc0d968b473345b3b6f817cdaf4b3dac Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Thu, 25 Jan 2024 20:10:32 +0800 Subject: [PATCH] chore: check before get userGroup --- middleware/distributor.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/middleware/distributor.go b/middleware/distributor.go index 74754f4..51945a4 100644 --- a/middleware/distributor.go +++ b/middleware/distributor.go @@ -18,8 +18,6 @@ type ModelRequest struct { func Distribute() func(c *gin.Context) { return func(c *gin.Context) { userId := c.GetInt("id") - userGroup, _ := model.CacheGetUserGroup(userId) - c.Set("group", userGroup) var channel *model.Channel channelId, ok := c.Get("channelId") if ok { @@ -98,6 +96,10 @@ func Distribute() func(c *gin.Context) { return } } + + userGroup, _ := model.CacheGetUserGroup(userId) + c.Set("group", userGroup) + channel, err = model.CacheGetRandomSatisfiedChannel(userGroup, modelRequest.Model) if err != nil { message := fmt.Sprintf("当前分组 %s 下对于模型 %s 无可用渠道", userGroup, modelRequest.Model)