aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-05-13 21:14:29 +0700
committerShulhan <ms@kilabit.info>2022-05-13 21:14:29 +0700
commit20c3f80e7dfd9e453d757199beb2137c09a9f536 (patch)
tree82711df23adee40b578a4da395a9588877132d88 /client.go
parentc9de13ce2432dee7d58fb45c4cecbf026786a48d (diff)
downloadrescached-20c3f80e7dfd9e453d757199beb2137c09a9f536.tar.xz
cmd/resolver: implement command to delete record on hosts file
The command has the following signature, resolver hosts.d rr delete <name> <domain> Given the hosts name "hosts" and domain "my.hosts" it will delete all records that have domain name "my.hosts" inside the file.
Diffstat (limited to 'client.go')
-rw-r--r--client.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/client.go b/client.go
index cc4399e..49f6a12 100644
--- a/client.go
+++ b/client.go
@@ -380,3 +380,34 @@ func (cl *Client) HostsdRecordAdd(hostsName, domain, value string) (record *dns.
return record, nil
}
+
+// HostsdRecordDelete delete a record from hosts file by domain name.
+func (cl *Client) HostsdRecordDelete(hostsName, domain string) (record *dns.ResourceRecord, err error) {
+ var (
+ logp = "HostsdRecordDelete"
+ res = libhttp.EndpointResponse{
+ Data: &record,
+ }
+ params = url.Values{}
+
+ resb []byte
+ )
+
+ params.Set(paramNameName, hostsName)
+ params.Set(paramNameDomain, domain)
+
+ _, resb, err = cl.Delete(apiHostsdRR, nil, params)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+
+ err = json.Unmarshal(resb, &res)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+ if res.Code != http.StatusOK {
+ return nil, fmt.Errorf("%s: %d %s", logp, res.Code, res.Message)
+ }
+
+ return record, nil
+}