From ac6b10489e1630b150f0c8d822cf31a649cea897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 24 Apr 2023 09:37:26 +0800 Subject: [PATCH] =?UTF-8?q?DNSPod=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=BA=BF=E8=B7=AF=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnspod/response_custom_line_group_list.go | 17 +++++++ internal/dnsclients/provider_dnspod.go | 47 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 internal/dnsclients/dnspod/response_custom_line_group_list.go diff --git a/internal/dnsclients/dnspod/response_custom_line_group_list.go b/internal/dnsclients/dnspod/response_custom_line_group_list.go new file mode 100644 index 00000000..fbb73d49 --- /dev/null +++ b/internal/dnsclients/dnspod/response_custom_line_group_list.go @@ -0,0 +1,17 @@ +// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . + +package dnspod + +type CustomLineGroupListResponse struct { + BaseResponse + + Data struct { + LineGroups []struct { + Name string `json:"name"` + } `json:"line_groups"` + Info struct { + NowTotal int `json:"now_total"` + Total int `json:"total"` + } `json:"info"` + } `json:"data"` +} diff --git a/internal/dnsclients/provider_dnspod.go b/internal/dnsclients/provider_dnspod.go index 1d304aee..bc17a73b 100644 --- a/internal/dnsclients/provider_dnspod.go +++ b/internal/dnsclients/provider_dnspod.go @@ -164,6 +164,53 @@ func (this *DNSPodProvider) GetRoutes(domain string) (routes []*dnstypes.Route, }) } + // 自定义线路分组 + var groupsPerPage = 100 + var customLineGroupListResponse = new(dnspod.CustomLineGroupListResponse) + err = this.doAPI("/Custom.Line.Group.List", map[string]string{ + "domain": domain, + "offset": "0", + "length": types.String(groupsPerPage), + }, customLineGroupListResponse) + if err != nil { + // 忽略自定义分组错误 + err = nil + } else { + if len(customLineGroupListResponse.Data.LineGroups) > 0 { + for _, lineGroup := range customLineGroupListResponse.Data.LineGroups { + routes = append(routes, &dnstypes.Route{ + Name: "分组:" + lineGroup.Name, + Code: lineGroup.Name, + }) + } + } + + if customLineGroupListResponse.Data.Info.Total > customLineGroupListResponse.Data.Info.NowTotal { + for page := 1; page <= 100; /** 最多100页 **/ page++ { + err = this.doAPI("/Custom.Line.Group.List", map[string]string{ + "domain": domain, + "offset": types.String(page * groupsPerPage), + "length": types.String(groupsPerPage), + }, customLineGroupListResponse) + if err != nil { + // 忽略错误 + err = nil + } else { + if len(customLineGroupListResponse.Data.LineGroups) == 0 { + break + } + + for _, lineGroup := range customLineGroupListResponse.Data.LineGroups { + routes = append(routes, &dnstypes.Route{ + Name: "分组:" + lineGroup.Name, + Code: lineGroup.Name, + }) + } + } + } + } + } + return routes, nil }