-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodels.go
102 lines (92 loc) · 2.99 KB
/
models.go
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
package alidns
import (
"strings"
"time"
"github.com/libdns/libdns"
)
// aliRecList:the struct of query result
type aliRecList struct {
ReqID string `json:"RequestId,omitempty"`
TotalCount int `json:"TotalCount,omitempty"`
PgSize int `json:"PageSize,omitempty"`
DRecords aliDomaRecords `json:"DomainRecords,omitempty"`
PgNum int `json:"PageNumber,omitempty"`
}
type aliDomaRecord struct {
Rr string `json:"RR,omitempty"`
Line string `json:"Line,omitempty"`
Status string `json:"Status,omitempty"`
Locked bool `json:"Locked,omitempty"`
DTyp string `json:"Type,omitempty"`
DName string `json:"DomainName,omitempty"`
DVal string `json:"Value,omitempty"`
RecID string `json:"RecordId,omitempty"`
TTL int `json:"TTL,omitempty"`
Weight int `json:"Weight,omitempty"`
}
type aliDomaRecords struct {
Record []aliDomaRecord `json:"Record,omitempty"`
}
type aliResult struct {
ReqID string `json:"RequestId,omitempty"`
DRecords aliDomaRecords `json:"DomainRecords,omitempty"`
DLvl int `json:"DomainLevel,omitempty"`
DVal string `json:"Value,omitempty"`
TTL int `json:"TTL,omitempty"`
DName string `json:"DomainName,omitempty"`
Rr string `json:"RR,omitempty"`
Msg string `json:"Message,omitempty"`
Rcmd string `json:"Recommend,omitempty"`
HostID string `json:"HostId,omitempty"`
Code string `json:"Code,omitempty"`
TotalCount int `json:"TotalCount,omitempty"`
PgSize int `json:"PageSize,omitempty"`
PgNum int `json:"PageNumber,omitempty"`
DTyp string `json:"Type,omitempty"`
RecID string `json:"RecordId,omitempty"`
Line string `json:"Line,omitempty"`
Status string `json:"Status,omitempty"`
Locked bool `json:"Locked,omitempty"`
Weight int `json:"Weight,omitempty"`
MinTTL int `json:"MinTtl,omitempty"`
}
func (r *aliDomaRecord) LibdnsRecord() libdns.Record {
return libdns.Record{
ID: r.RecID,
Type: r.DTyp,
Name: r.Rr,
Value: r.DVal,
TTL: time.Duration(r.TTL) * time.Second,
}
}
func (r *aliResult) ToDomaRecord() aliDomaRecord {
return aliDomaRecord{
RecID: r.RecID,
DTyp: r.DTyp,
Rr: r.Rr,
DName: r.DName,
DVal: r.DVal,
TTL: r.TTL,
Line: r.Line,
Status: r.Status,
Locked: r.Locked,
Weight: r.Weight,
}
}
// AlidnsRecord convert libdns.Record to aliDomaRecord
func alidnsRecord(r libdns.Record) aliDomaRecord {
return aliDomaRecord{
Rr: r.Name,
DTyp: r.Type,
DVal: r.Value,
RecID: r.ID,
TTL: int(r.TTL.Seconds()),
}
}
// AlidnsRecord convert libdns.Record with zone to aliDomaRecord
func alidnsRecordWithZone(r libdns.Record, zone string) aliDomaRecord {
r.Name = libdns.RelativeName(r.Name, zone)
rec := alidnsRecord(r)
rec.DName = strings.Trim(zone, ".")
return rec
}