浏览代码

refactor(internal/service): 优化全局限流服务中的变量使用

- 修改变量命名,提高代码可读性
- 修正变量使用顺序,确保逻辑正确性
-增加必要的注释,解释关键步骤
fusu 1 月之前
父节点
当前提交
06d2998ee7
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      internal/service/globallimit.go

+ 5 - 2
internal/service/globallimit.go

@@ -158,13 +158,14 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
 	var userId int64
 	var groupId int64
 	g.Go(func() error {
-		gatewayGroupId, e := s.gateWayGroupRep.GetGatewayGroupWhereHostIdNull(gCtx, require.Operator, require.IpCount)
+		res, e := s.gateWayGroupRep.GetGatewayGroupWhereHostIdNull(gCtx, require.Operator, require.IpCount)
 		if e != nil {
 			return e
 		}
-		if gatewayGroupId == 0 {
+		if res == 0 {
 			return fmt.Errorf("获取网关组失败")
 		}
+		gatewayGroupId = res
 		return nil
 	})
 
@@ -190,6 +191,7 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
 		if res == 0 {
 			return fmt.Errorf("创建规则分组失败")
 		}
+		groupId = res
 		return nil
 	})
 
@@ -198,6 +200,7 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
 	}
 
 	ruleId, err := s.cdnService.BindPlan(ctx, v1.Plan{
+		UserId:    userId,
 
 	})