-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.go
More file actions
82 lines (77 loc) · 1.83 KB
/
models.go
File metadata and controls
82 lines (77 loc) · 1.83 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
package libdns
import (
"encoding/json"
"strconv"
"time"
"github.com/console-dns/spec/models"
"github.com/libdns/libdns"
)
func ToLDnsA(name string, a *models.RecordA) libdns.Record {
marshal, _ := json.Marshal(a)
return libdns.Record{
ID: string(marshal),
Type: "A",
Name: name,
Value: a.Ip.String(),
TTL: time.Duration(a.Ttl) * time.Second,
}
}
func ToLDnsAAAA(name string, a *models.RecordAAAA) libdns.Record {
marshal, _ := json.Marshal(a)
return libdns.Record{
ID: string(marshal),
Type: "AAAA",
Name: name,
Value: a.Ip.String(),
TTL: time.Duration(a.Ttl) * time.Second,
}
}
func ToLDnsTXT(name string, a *models.RecordTXT) libdns.Record {
marshal, _ := json.Marshal(a)
return libdns.Record{
ID: string(marshal),
Type: "TXT",
Name: name,
Value: a.Text,
TTL: time.Duration(a.Ttl) * time.Second,
}
}
func FromLDnsA(r *libdns.Record) (old, new *models.RecordA, err error) {
old = &models.RecordA{}
if r.ID != "" {
err = json.Unmarshal([]byte(r.ID), old)
if err != nil {
return nil, nil, err
}
} else {
old = nil
}
a, err := models.NewRecordA(r.Value, strconv.Itoa(int(r.TTL.Seconds())))
return old, a, err
}
func FromLDnsAAAA(r *libdns.Record) (old, new *models.RecordAAAA, err error) {
old = &models.RecordAAAA{}
if r.ID != "" {
err = json.Unmarshal([]byte(r.ID), old)
if err != nil {
return nil, nil, err
}
} else {
old = nil
}
new, err = models.NewRecordAAAA(r.Value, strconv.Itoa(int(r.TTL.Seconds())))
return old, new, err
}
func FromLDnsTXT(r *libdns.Record) (old, new *models.RecordTXT, err error) {
old = &models.RecordTXT{}
if r.ID != "" {
err = json.Unmarshal([]byte(r.ID), old)
if err != nil {
return nil, nil, err
}
} else {
old = nil
}
new, err = models.NewRecordTXT(r.Value, strconv.Itoa(int(r.TTL.Seconds())))
return old, new, err
}