-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmodel.go
More file actions
47 lines (40 loc) · 996 Bytes
/
model.go
File metadata and controls
47 lines (40 loc) · 996 Bytes
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
package hetzner
import (
"github.com/libdns/libdns"
"time"
)
// Zone is the zone type for Hetzner.
type Zone struct {
ID string `json:"id"`
}
// Record is the record type for Hetzner implementing the libdns.Record interface.
type Record struct {
ID string `json:"id,omitempty"`
ZoneID string `json:"zone_id,omitempty"`
Type string `json:"type"`
Name string `json:"name"`
Value string `json:"value"`
TTL int `json:"ttl"`
}
// RR implements the libdns.Record interface.
func (r *Record) RR() libdns.RR {
return libdns.RR{
Name: r.Name,
TTL: time.Duration(r.TTL) * time.Second,
Type: r.Type,
Data: r.Value,
}
}
// Parse parses a record from the Hetzner API response into libdns.Record.
func (r *Record) Parse(zone string) (libdns.Record, error) {
rr, err := libdns.RR{
Name: libdns.RelativeName(r.Name, zone),
TTL: time.Duration(r.TTL) * time.Second,
Type: r.Type,
Data: r.Value,
}.Parse()
if err != nil {
return nil, err
}
return rr, nil
}