docs: 网关限流接口文档补充操作、类别与状态枚举
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 15m23s
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 15m23s
- 限流组与错误分类的操作数组元素改为具名类型 GatewayOperation,接口文档按元素给出可选值 - 匹配方式、错误类别、状态字段补充 enum 标签;高优先级操作说明补充取值与必填条件
This commit is contained in:
@@ -240,12 +240,12 @@ func (s *GatewayRateLimitService) validateGroup(ctx context.Context, req *dto.Sa
|
||||
if req.ReservedQPS >= req.MaxQPS {
|
||||
return errors.New(errors.CodeInvalidParam, "预留额度必须小于每秒请求上限")
|
||||
}
|
||||
ops := uniqueStrings(req.Operations)
|
||||
ops := uniqueStrings(operationStrings(req.Operations))
|
||||
opSet := map[string]bool{}
|
||||
for _, op := range ops {
|
||||
opSet[op] = true
|
||||
}
|
||||
for _, op := range req.HighPriorityOperations {
|
||||
for _, op := range operationStrings(req.HighPriorityOperations) {
|
||||
if !opSet[op] {
|
||||
return errors.New(errors.CodeInvalidParam, "高优先级操作必须属于组内操作:"+constants.GatewayOperationName(op))
|
||||
}
|
||||
@@ -304,8 +304,8 @@ func applyGroupRequest(row *model.CarrierRateLimitGroup, req *dto.SaveRateLimitG
|
||||
row.GroupName = strings.TrimSpace(req.GroupName)
|
||||
row.MaxQPS = req.MaxQPS
|
||||
row.ReservedQPS = req.ReservedQPS
|
||||
row.Operations = encodeStrings(uniqueStrings(req.Operations))
|
||||
row.HighPriorityOperations = encodeStrings(uniqueStrings(req.HighPriorityOperations))
|
||||
row.Operations = encodeStrings(uniqueStrings(operationStrings(req.Operations)))
|
||||
row.HighPriorityOperations = encodeStrings(uniqueStrings(operationStrings(req.HighPriorityOperations)))
|
||||
if req.Status != nil {
|
||||
row.Status = *req.Status
|
||||
}
|
||||
@@ -522,7 +522,7 @@ func applyRuleRequest(row *model.GatewayErrorClassification, req *dto.SaveGatewa
|
||||
row.Keyword = strings.TrimSpace(req.Keyword)
|
||||
row.MatchType = req.MatchType
|
||||
row.Category = req.Category
|
||||
row.Operations = encodeStrings(uniqueStrings(req.Operations))
|
||||
row.Operations = encodeStrings(uniqueStrings(operationStrings(req.Operations)))
|
||||
row.Priority = req.Priority
|
||||
if row.Priority == 0 {
|
||||
row.Priority = 100
|
||||
@@ -594,6 +594,14 @@ func uniqueStrings(values []string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
func operationStrings(values []dto.GatewayOperation) []string {
|
||||
out := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
out = append(out, string(value))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func encodeStrings(values []string) datatypes.JSON {
|
||||
if values == nil {
|
||||
values = []string{}
|
||||
|
||||
Reference in New Issue
Block a user