-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.go
68 lines (60 loc) · 1.43 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
package timeweb
import (
"fmt"
"github.com/libdns/libdns"
)
type RecordResponse struct {
Data struct {
Priority uint `json:"priority,omitempty"`
Value string `json:"value"`
} `json:"data"`
ID uint `json:"id"`
Type string `json:"type"`
Fqdn string `json:"fqdn"`
}
type RecordsResponse struct {
Meta struct {
Total int `json:"total"`
} `json:"meta"`
DNSRecords []RecordResponse `json:"dns_records"`
}
type Record struct {
Subdomain string `json:"subdomain"`
Type string `json:"type"`
Value string `json:"value"`
}
type SavedRecord struct {
DNSRecord struct {
ID uint `json:"id"`
Type string `json:"type"`
Data struct {
Priority uint `json:"priority,omitempty"`
Value string `json:"value"`
Subdomain string `json:"subdomain"`
}
} `json:"dns_record"`
}
func (r *SavedRecord) libDNSRecord(zone string) libdns.Record {
return libdns.Record{
ID: fmt.Sprintf("%d", r.DNSRecord.ID),
Name: libdns.RelativeName(r.DNSRecord.Data.Subdomain, zone),
Type: r.DNSRecord.Type,
Value: r.DNSRecord.Data.Value,
}
}
func (r *RecordResponse) libDNSRecord(zone string) libdns.Record {
return libdns.Record{
ID: fmt.Sprintf("%d", r.ID),
Name: libdns.RelativeName(r.Fqdn, zone),
Type: r.Type,
Value: r.Data.Value,
Priority: r.Data.Priority,
}
}
func libdnsToRecord(r libdns.Record) Record {
return Record{
Type: r.Type,
Value: r.Value,
Subdomain: r.Name,
}
}