/
client_zones.go
91 lines (71 loc) · 1.78 KB
/
client_zones.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package luadns
// ListZones returns user zones.
//
// See: http://www.luadns.com/api.html#list-zones
func (c *Client) ListZones() ([]*Zone, error) {
zones := []*Zone{}
req := func() ([]byte, error) {
return c.client.Get(c.endpoint("/zones"))
}
err := c.do(req, &zones)
if err != nil {
return nil, err
}
return zones, nil
}
// CreateZone creates a new zone using supplied attributes.
//
// See: http://www.luadns.com/api.html#create-a-zone
func (c *Client) CreateZone(attrs *Zone) (*Zone, error) {
var zone Zone
req := func() ([]byte, error) {
return c.client.Post(c.endpoint("/zones"), attrs)
}
err := c.do(req, &zone)
if err != nil {
return nil, err
}
return &zone, nil
}
// GetZone get a specific zone identfied by `zoneID`.
//
// See: http://www.luadns.com/api.html#get-a-zone
func (c *Client) GetZone(zoneID int64) (*Zone, error) {
var zone Zone
req := func() ([]byte, error) {
return c.client.Get(c.endpoint("/zones/%d", zoneID))
}
err := c.do(req, &zone)
if err != nil {
return nil, err
}
return &zone, nil
}
// UpdateZone zone identified by `zoneID` using supplied attributes.
//
// See: http://www.luadns.com/api.html#update-a-zone
func (c *Client) UpdateZone(zoneID int64, attrs *Zone) (*Zone, error) {
var zone Zone
req := func() ([]byte, error) {
return c.client.Put(c.endpoint("/zones/%d", zoneID), attrs)
}
err := c.do(req, &zone)
if err != nil {
return nil, err
}
return &zone, nil
}
// DeleteZone delete specific zone using zone ID.
//
// See: http://www.luadns.com/api.html#delete-a-zone
func (c *Client) DeleteZone(zoneID int64) (*Zone, error) {
var zone Zone
req := func() ([]byte, error) {
return c.client.Delete(c.endpoint("/zones/%d", zoneID))
}
err := c.do(req, &zone)
if err != nil {
return nil, err
}
return &zone, nil
}