-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.go
68 lines (59 loc) · 1.54 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 porkbun
import (
"fmt"
"github.com/libdns/libdns"
"strconv"
"time"
)
type pkbnRecord struct {
Content string `json:"content"`
ID string `json:"id"`
Name string `json:"name"`
Notes string `json:"notes"`
Prio string `json:"prio"`
TTL string `json:"ttl"`
Type string `json:"type"`
}
type pkbnRecordsResponse struct {
Records []pkbnRecord `json:"records"`
Status string `json:"status"`
}
type ApiCredentials struct {
Apikey string `json:"apikey"`
Secretapikey string `json:"secretapikey"`
}
type pkbnResponseStatus struct {
Status string `json:"status"`
Message string `json:"message,omitempty"`
}
type pkbnPingResponse struct {
pkbnResponseStatus
YourIP string `json:"yourIp"`
}
type pkbnCreateResponse struct {
pkbnResponseStatus
// TODO contact support endpoint isn't returning the ID despite it being in their docs.
// ID string `json:"id"`
}
func (record pkbnRecord) toLibdnsRecord(zone string) libdns.Record {
ttl, _ := time.ParseDuration(record.TTL + "s")
priority, _ := strconv.Atoi(record.Prio)
return libdns.Record{
ID: record.ID,
Name: libdns.RelativeName(record.Name, LibdnsZoneToPorkbunDomain(zone)),
Priority: uint(priority),
TTL: ttl,
Type: record.Type,
Value: record.Content,
}
}
func (a pkbnResponseStatus) Error() string {
return fmt.Sprintf("%s: %s", a.Status, a.Message)
}
type pkbnRecordPayload struct {
*ApiCredentials
Content string `json:"content"`
Name string `json:"name"`
TTL string `json:"ttl"`
Type string `json:"type"`
}