forked from libdns/tencentcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
106 lines (89 loc) · 2.12 KB
/
types.go
File metadata and controls
106 lines (89 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package tencentcloud
import (
"errors"
"strconv"
"time"
"github.com/libdns/libdns"
)
var ErrRecordNotFound = errors.New("record not found")
var ErrNotValid = errors.New("returned value is not valid")
type Provider struct {
SecretId string
SecretKey string
SessionToken string
Region string
}
type CreateModifyRecordRequest struct {
Domain string `json:"Domain"`
SubDomain string `json:"SubDomain,omitempty"`
RecordType string `json:"RecordType,omitempty"`
RecordLine string `json:"RecordLine,omitempty"`
Value string `json:"Value,omitempty"`
TTL int64 `json:"TTL,omitempty"`
RecordId uint64 `json:"RecordId,omitempty"`
}
type FindRecordRequest struct {
Domain string `json:"Domain"`
RecordType string `json:"RecordType,omitempty"`
RecordLine string `json:"RecordLine,omitempty"`
Subdomain string `json:"Subdomain,omitempty"`
Limit int64 `json:"Limit,omitempty"`
}
type DeleteRecordRequest struct {
Domain string `json:"Domain"`
RecordId uint64 `json:"RecordId"`
}
type Response struct {
Response ResponseData `json:"Response"`
}
type ResponseData struct {
RecordList []RecordInfo `json:"RecordList,omitempty"`
RecordId uint64 `json:"RecordId,omitempty"`
Error *ErrorInfo `json:"Error,omitempty"`
}
type RecordInfo struct {
RecordId int64 `json:"RecordId"`
Type string `json:"Type"`
Name string `json:"Name"`
Value string `json:"Value"`
TTL int64 `json:"TTL"`
MX int `json:"MX,omitempty"`
}
type ErrorInfo struct {
Code string `json:"Code"`
Message string `json:"Message"`
}
type record struct {
Type string
Name string
Value string
TTL time.Duration
MX int
}
func (r record) libdnsRecord() (libdns.Record, error) {
if r.Type == "MX" {
r.Value = strconv.Itoa(r.MX) + " " + r.Value
}
return libdns.RR{
Type: r.Type,
Name: r.Name,
Data: r.Value,
TTL: r.TTL,
}.Parse()
}
func fromLibdnsRecord(r libdns.Record) record {
rr := r.RR()
host := rr.Name
if host == "@" {
host = ""
}
if rr.TTL == 0 {
rr.TTL = 600
}
return record{
Type: rr.Type,
Name: host,
Value: rr.Data,
TTL: rr.TTL,
}
}