diff options
| author | Shulhan <ms@kilabit.info> | 2022-05-13 21:14:29 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-05-13 21:14:29 +0700 |
| commit | 20c3f80e7dfd9e453d757199beb2137c09a9f536 (patch) | |
| tree | 82711df23adee40b578a4da395a9588877132d88 /client.go | |
| parent | c9de13ce2432dee7d58fb45c4cecbf026786a48d (diff) | |
| download | rescached-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.go | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -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 +} |
