aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-04-15 01:52:25 +0700
committerShulhan <ms@kilabit.info>2022-04-15 01:52:25 +0700
commit618ffca939c176b2faea4d18de756d58f1110639 (patch)
tree7cc43c0c9a3d7140fe1008775c75b22f4d68f94c /client.go
parent4d3ab7f49410eb2b774a7c9e25ba10a1efbd1413 (diff)
downloadrescached-618ffca939c176b2faea4d18de756d58f1110639.tar.xz
all: implement sub command to remove caches by domain name
The "caches" command accept second sub command "remove" that accept single domain name to be removed from caches. This changes affect the HTTP API for caches delete to return the removed answer on the response data.
Diffstat (limited to 'client.go')
-rw-r--r--client.go35
1 files changed, 31 insertions, 4 deletions
diff --git a/client.go b/client.go
index ecf6e62..289f031 100644
--- a/client.go
+++ b/client.go
@@ -60,6 +60,36 @@ func (cl *Client) Caches() (answers []*dns.Answer, err error) {
return answers, nil
}
+func (cl *Client) CachesRemove(q string) (listAnswer []*dns.Answer, err error) {
+ var (
+ logp = "CachesRemove"
+ params = url.Values{}
+ res = libhttp.EndpointResponse{
+ Data: &listAnswer,
+ }
+
+ resb []byte
+ )
+
+ params.Set(paramNameName, q)
+
+ _, resb, err = cl.Delete(apiCaches, 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 listAnswer, nil
+}
+
// CachesSearch search the answer in caches by its domain name and return it
// as DNS message.
func (cl *Client) CachesSearch(q string) (listMsg []*dns.Message, err error) {
@@ -70,15 +100,12 @@ func (cl *Client) CachesSearch(q string) (listMsg []*dns.Message, err error) {
Data: &listMsg,
}
- path string
resb []byte
)
params.Set(paramNameQuery, q)
- path = apiCachesSearch + "?" + params.Encode()
- fmt.Printf("%s: path: %s\n", logp, path)
- _, resb, err = cl.Get(path, nil, nil)
+ _, resb, err = cl.Get(apiCachesSearch, nil, params)
if err != nil {
return nil, fmt.Errorf("%s: %w", logp, err)
}