Skip to content

Commit 7217785

Browse files
committed
域名解析增加CloudFlare DNS支持
1 parent 55d3ba4 commit 7217785

15 files changed

Lines changed: 582 additions & 40 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2+
3+
package cloudflare
4+
5+
type BaseResponse struct {
6+
Success bool `json:"success"`
7+
Errors []struct {
8+
Code int `json:"code"`
9+
Message string `json:"message"`
10+
} `json:"errors"`
11+
}
12+
13+
func (this *BaseResponse) IsOk() bool {
14+
return this.Success
15+
}
16+
17+
func (this *BaseResponse) LastError() (code int, message string) {
18+
if len(this.Errors) == 0 {
19+
return 0, ""
20+
}
21+
return this.Errors[0].Code, this.Errors[0].Message
22+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2+
3+
package cloudflare
4+
5+
type CreateDNSRecordResponse struct {
6+
BaseResponse
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2+
3+
package cloudflare
4+
5+
type DeleteDNSRecordResponse struct {
6+
BaseResponse
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2+
3+
package cloudflare
4+
5+
type GetDNSRecordsResponse struct {
6+
BaseResponse
7+
8+
Result []struct {
9+
Id string `json:"id"`
10+
Type string `json:"type"`
11+
Name string `json:"name"`
12+
Content string `json:"content"`
13+
Ttl int `json:"ttl"`
14+
ZoneId string `json:"zoneId"`
15+
ZoneName string `json:"zoneName"`
16+
} `json:"result"`
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2+
3+
package cloudflare
4+
5+
type ResponseInterface interface {
6+
IsOk() bool
7+
LastError() (code int, message string)
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2+
3+
package cloudflare
4+
5+
type UpdateDNSRecordResponse struct {
6+
BaseResponse
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
2+
3+
package cloudflare
4+
5+
type ZonesResponse struct {
6+
BaseResponse
7+
8+
Result []struct {
9+
Id string `json:"id"`
10+
Name string `json:"name"`
11+
} `json:"result"`
12+
}

internal/dnsclients/provider_alidns.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99
"strings"
1010
)
1111

12-
// 阿里云服务商
12+
// AliDNSProvider 阿里云服务商
1313
type AliDNSProvider struct {
1414
BaseProvider
1515

1616
accessKeyId string
1717
accessKeySecret string
1818
}
1919

20-
// 认证
20+
// Auth 认证
2121
func (this *AliDNSProvider) Auth(params maps.Map) error {
2222
this.accessKeyId = params.GetString("accessKeyId")
2323
this.accessKeySecret = params.GetString("accessKeySecret")
@@ -30,7 +30,7 @@ func (this *AliDNSProvider) Auth(params maps.Map) error {
3030
return nil
3131
}
3232

33-
// 获取域名列表
33+
// GetRecords 获取域名列表
3434
func (this *AliDNSProvider) GetRecords(domain string) (records []*Record, err error) {
3535
pageNumber := 1
3636
size := 100
@@ -70,7 +70,7 @@ func (this *AliDNSProvider) GetRecords(domain string) (records []*Record, err er
7070
return
7171
}
7272

73-
// 读取域名支持的线路数据
73+
// GetRoutes 读取域名支持的线路数据
7474
func (this *AliDNSProvider) GetRoutes(domain string) (routes []*Route, err error) {
7575
req := alidns.CreateDescribeSupportLinesRequest()
7676
req.DomainName = domain
@@ -89,7 +89,7 @@ func (this *AliDNSProvider) GetRoutes(domain string) (routes []*Route, err error
8989
return
9090
}
9191

92-
// 查询单个记录
92+
// QueryRecord 查询单个记录
9393
func (this *AliDNSProvider) QueryRecord(domain string, name string, recordType RecordType) (*Record, error) {
9494
records, err := this.GetRecords(domain)
9595
if err != nil {
@@ -103,7 +103,7 @@ func (this *AliDNSProvider) QueryRecord(domain string, name string, recordType R
103103
return nil, err
104104
}
105105

106-
// 设置记录
106+
// AddRecord 设置记录
107107
func (this *AliDNSProvider) AddRecord(domain string, newRecord *Record) error {
108108
req := alidns.CreateAddDomainRecordRequest()
109109
req.RR = newRecord.Name
@@ -124,7 +124,7 @@ func (this *AliDNSProvider) AddRecord(domain string, newRecord *Record) error {
124124
return errors.New(resp.GetHttpContentString())
125125
}
126126

127-
// 修改记录
127+
// UpdateRecord 修改记录
128128
func (this *AliDNSProvider) UpdateRecord(domain string, record *Record, newRecord *Record) error {
129129
req := alidns.CreateUpdateDomainRecordRequest()
130130
req.RecordId = record.Id
@@ -138,7 +138,7 @@ func (this *AliDNSProvider) UpdateRecord(domain string, record *Record, newRecor
138138
return err
139139
}
140140

141-
// 删除记录
141+
// DeleteRecord 删除记录
142142
func (this *AliDNSProvider) DeleteRecord(domain string, record *Record) error {
143143
req := alidns.CreateDeleteDomainRecordRequest()
144144
req.RecordId = record.Id
@@ -148,7 +148,7 @@ func (this *AliDNSProvider) DeleteRecord(domain string, record *Record) error {
148148
return err
149149
}
150150

151-
// 默认线路
151+
// DefaultRoute 默认线路
152152
func (this *AliDNSProvider) DefaultRoute() string {
153153
return "default"
154154
}

0 commit comments

Comments
 (0)