-
Notifications
You must be signed in to change notification settings - Fork 0
/
records.go
63 lines (52 loc) · 1.88 KB
/
records.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
package gandiapi
import (
"io/ioutil"
"net/http"
)
// Record represents a Record object.
type Record struct {
RrsetType string `json:"rrset_type"`
RrsetTTL int `json:"rrset_ttl,omitempty"`
RrsetName string `json:"rrset_name"`
RrsetHref string `json:"rrset_href,omitempty"`
RrsetValues []string `json:"rrset_values"`
}
// GetRecords returns a slice of Record.
func (c *Client) GetRecords(fqdn string) (records []Record, err error) {
_, err = c.get("livedns/domains/"+fqdn+"/records", nil, &records)
return
}
// GetRecordsText returns a text version of the zone.
func (c *Client) GetRecordsText(fqdn string) (string, error) {
var resp http.Request
_, err := c.get("livedns/domains/"+fqdn+"/records", nil, &resp)
if err != nil {
return "", err
}
textRecordData, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
text := string(textRecordData)
return text, nil
}
// CreateRecord adds a new record for a given zone.
func (c *Client) CreateRecord(data Record, fqdn string) (response StandardResponse, err error) {
_, err = c.post("livedns/domains/"+fqdn+"/records", data, &response)
return
}
// GetRecord returns a the single requested record for the given fqdn, if it exists.
func (c *Client) GetRecord(fqdn, recordName, recordType string) (record Record, err error) {
_, err = c.get("livedns/domains/"+fqdn+"/records/"+recordName+"/"+recordType, nil, &record)
return
}
// UpdateRecord updates an existing record with the provided value.
func (c *Client) UpdateRecord(data Record, fqdn string) (response StandardResponse, err error) {
c.put("livedns/domains/"+fqdn+"/records/"+data.RrsetName+"/"+data.RrsetType, data, &response)
return
}
// DeleteRecord removes a given record name.
func (c *Client) DeleteRecord(fqdn, recordName, recordType string) (err error) {
c.put("livedns/domains/"+fqdn+"/records/"+recordName+"/"+recordType, nil, nil)
return
}