-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
46 lines (39 loc) · 987 Bytes
/
helpers.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
package luadns
import (
"strconv"
"strings"
"time"
"github.com/libdns/libdns"
"github.com/luadns/luadns-go"
)
// unFQDN trims any trailing "." from fqdn name.
func unFQDN(fqdn string) string {
return strings.TrimSuffix(fqdn, ".")
}
// newLibRecord builds a libdns Record from the provider Record.
func newLibRecord(r *luadns.Record, zone string) libdns.Record {
return libdns.Record{
ID: strconv.FormatInt(r.ID, 10),
Type: r.Type,
Name: libdns.RelativeName(r.Name, zone),
Value: r.Content,
TTL: time.Duration(r.TTL) * time.Second,
}
}
// newLuaRecord builds a provider Record from the libdns Record.
func newLuaRecord(r libdns.Record, zone string) (*luadns.Record, error) {
pr := &luadns.Record{
Type: r.Type,
Name: libdns.AbsoluteName(r.Name, zone),
Content: r.Value,
TTL: uint32(r.TTL.Seconds()),
}
if r.ID != "" {
n, err := strconv.ParseInt(r.ID, 10, 64)
if err != nil {
return nil, err
}
pr.ID = n
}
return pr, nil
}