-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
93 lines (79 loc) · 2.55 KB
/
types.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
package nodion
import (
"fmt"
"strings"
"time"
)
// Record types.
const (
TypeA = "a"
TypeAAAA = "aaaa"
TypeNS = "ns"
TypeALIAS = "alias"
TypeCNAME = "cname"
TypeMX = "mx"
TypeTXT = "txt"
TypePTR = "ptr"
TypeSRV = "srv"
)
// ZonesResponse represents the response of the GetZones API endpoint.
type ZonesResponse struct {
Zones []Zone `json:"dns_zones"`
}
// ZoneResponse represents the response of the CreateZone API endpoint.
type ZoneResponse struct {
Zone Zone `json:"dns_zone"`
}
// RecordsResponse represents the response of the GetRecords API endpoint.
type RecordsResponse struct {
Records []Record `json:"records"`
}
// RecordResponse represents the response of the CreateRecord API endpoint.
type RecordResponse struct {
Record Record `json:"record"`
}
// DeleteResponse represents the response of the API endpoints related to deletion of zone or record.
type DeleteResponse struct {
Deleted bool `json:"deleted"`
}
// Zone contains all the information related to a zone.
type Zone struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
Records []Record `json:"records,omitempty"`
}
// Record contains all the information related to a DNS record.
type Record struct {
ID string `json:"id,omitempty"`
RecordType string `json:"record_type,omitempty"` // a, aaaa, ns, alias, cname, mx, txt, ptr, srv. Case-sensitive must be in lowercase.
Name string `json:"name,omitempty"`
Content string `json:"content,omitempty"`
TTL int `json:"ttl,omitempty"` // a number between 60 and 86400.
ZoneID string `json:"zone_id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
// ZonesFilter is filter criteria for zones.
type ZonesFilter struct {
Name string `url:"name"` // must be the exact name and no FQDN
}
// RecordsFilter is filter criteria for records.
type RecordsFilter struct {
Name string `url:"name"`
RecordType string `url:"record_type"`
Content string `url:"content"`
}
// APIError is the error returned by the server.
type APIError struct {
StatusCode int `json:"status"`
Message string `json:"error"`
Errors []string `json:"errors"`
}
func (a *APIError) Error() string {
if a.Message != "" {
return fmt.Sprintf("status code %d: %s", a.StatusCode, a.Message)
}
return fmt.Sprintf("status code %d: %s", a.StatusCode, strings.Join(a.Errors, ", "))
}