From 20c3f80e7dfd9e453d757199beb2137c09a9f536 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 13 May 2022 21:14:29 +0700 Subject: cmd/resolver: implement command to delete record on hosts file The command has the following signature, resolver hosts.d rr delete Given the hosts name "hosts" and domain "my.hosts" it will delete all records that have domain name "my.hosts" inside the file. --- client.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'client.go') 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 +} -- cgit v1.3