|
@@ -194,27 +194,48 @@ func (s *aoDunService) AddWhiteStaticList(ctx context.Context, isSmall bool, req
|
|
|
|
|
|
// GetWhiteStaticList 查询白名单 IP 并返回其 ID
|
|
|
func (s *aoDunService) GetWhiteStaticList(ctx context.Context, isSmall bool, ip string, color string) (int, error) {
|
|
|
- formData := map[string]interface{}{
|
|
|
- "action": "get",
|
|
|
- "bwflag": color,
|
|
|
- "page": 1,
|
|
|
- "ip": ip,
|
|
|
- }
|
|
|
+ // 使用一个无限循环,直到API返回空数据页才停止
|
|
|
+ for i := 0; ; i++ { // i++ 会持续请求下一页
|
|
|
+ formData := map[string]interface{}{
|
|
|
+ "action": "get",
|
|
|
+ "bwflag": color,
|
|
|
+ "page": i,
|
|
|
+ "ip": ip,
|
|
|
+ }
|
|
|
|
|
|
- var res v1.IpGetResponse
|
|
|
- err := s.sendAuthenticatedRequest(ctx, isSmall, "/v1.0/firewall/static_bw_list", formData, &res)
|
|
|
- if err != nil {
|
|
|
- return 0, err
|
|
|
- }
|
|
|
+ var res v1.IpGetResponse
|
|
|
+ err := s.sendAuthenticatedRequest(ctx, isSmall, "/v1.0/firewall/static_bw_list", formData, &res)
|
|
|
+ if err != nil {
|
|
|
+ return 0, err // 网络或请求本身出错,直接返回
|
|
|
+ }
|
|
|
|
|
|
- if res.Code != 0 {
|
|
|
- return 0, fmt.Errorf("API 错误 (isSmall: %t): color %s,code %d, msg '%s'", isSmall, color, res.Code, res.Msg)
|
|
|
- }
|
|
|
- if len(res.Data) == 0 {
|
|
|
- return 0, fmt.Errorf("未找到 IP '%s' 相关的 '%s'名单记录 (isSmall: %t)", ip, color, isSmall)
|
|
|
+ if res.Code != 0 {
|
|
|
+ // API返回了业务错误,直接返回
|
|
|
+ return 0, fmt.Errorf("API 错误 (isSmall: %t): color %s,code %d, msg '%s'", isSmall, color, res.Code, res.Msg)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果当前页的数据为空,说明已经没有更多数据了,可以跳出循环。
|
|
|
+ // 这是分页查询结束的正确信号。
|
|
|
+ if len(res.Data) == 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ // 在当前页的数据中查找目标记录
|
|
|
+ for _, v := range res.Data {
|
|
|
+ if v.Remark == "宁波高防IP过白" {
|
|
|
+ // 找到了,立即返回ID
|
|
|
+ return v.ID, nil
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可选:为了防止无限循环,可以加一个最大页数限制
|
|
|
+ if i > 50 { // 比如最多查100页
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return res.Data[0].ID, nil
|
|
|
+ // 如果循环正常结束(所有页都查完了),说明没有找到符合条件的记录
|
|
|
+ return 0, fmt.Errorf("未找到 IP '%s' 相关的 '%s'名单记录 (备注: 宁波高防IP过白) (isSmall: %t)", ip, color, isSmall)
|
|
|
}
|
|
|
|
|
|
// DelWhiteStaticList 根据 ID 从白名单中删除 IP
|