-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns_delete.go
96 lines (80 loc) · 2.13 KB
/
dns_delete.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
92
93
94
95
96
package lbapi
import (
"errors"
"fmt"
"net/url"
)
// DeleteARecord deletes A or AAAA records.
func (c *Client) DeleteARecord(domain, value, host string, six bool) error {
if six {
return c.deleteRecord(APIDNSDeleteIPv6, domain, value, host)
}
return c.deleteRecord(APIDNSDeleteIPv4, domain, value, host)
}
// DeleteCNAME does exactly that.
func (c *Client) DeleteCNAME(domain, value, host string) error {
return c.deleteRecord(APIDNSDeleteCNAME, domain, value, host)
}
// DeleteMX holds no surprises.
func (c *Client) DeleteMX(domain, value, host string) error {
return c.deleteRecord(APIDNSDeleteMX, domain, value, host)
}
// DeleteNS is as boring as the above.
func (c *Client) DeleteNS(domain, value, host string) error {
return c.deleteRecord(APIDNSDeleteNS, domain, value, host)
}
// DeleteTXT deletes TXT records.
func (c *Client) DeleteTXT(domain, value, host string) error {
return c.deleteRecord(APIDNSDeleteTXT, domain, value, host)
}
// DeleteSRV deletes SRV records.
func (c *Client) DeleteSRV(domain, value, host string, port, weight uint16) error {
var err error
u, err := url.Parse(c.URL)
if err != nil {
return err
}
u.Path = APIDNSDeleteSRV
q := u.Query()
q.Set("auth-userid", c.ID)
q.Set("api-key", c.Key)
q.Set("domain-name", domain)
q.Set("value", value)
q.Set("host", host)
q.Set("port", fmt.Sprintf("%d", port))
q.Set("weight", fmt.Sprintf("%d", weight))
u.RawQuery = q.Encode()
res, err := PostResponse(c.Client, u.String())
if err != nil {
return err
}
list := *res
if list["status"] == "ERROR" {
return errors.New((fmt.Sprintf("%v", list["message"])))
}
return nil
}
func (c *Client) deleteRecord(call, domain, value, host string) error {
var err error
u, err := url.Parse(c.URL)
if err != nil {
return err
}
u.Path = call
q := u.Query()
q.Set("auth-userid", c.ID)
q.Set("api-key", c.Key)
q.Set("domain-name", domain)
q.Set("value", value)
q.Set("host", host)
u.RawQuery = q.Encode()
res, err := PostResponse(c.Client, u.String())
if err != nil {
return err
}
list := *res
if list["status"] == "ERROR" {
return errors.New((fmt.Sprintf("%v", list["message"])))
}
return nil
}