From a33c4f7e3c9bf4b9c394a0be426b4a6740382aee Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 15 Apr 2022 02:56:59 +0700 Subject: all: implement API to remove all caches On the HTTP side, if the query parameter "name" for "DELETE /api/caches" is "all" it will remove all caches. On the resolver side, if the parameter for "caches remove" is "all" it will remove all caches. This changes require latest lib/dns on share module. --- _doc/resolver.1.gz | Bin 2125 -> 2143 bytes _doc/resolver.adoc | 1 + cmd/resolver/main.go | 1 + go.mod | 2 +- go.sum | 4 ++-- httpd.go | 11 +++++++---- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/_doc/resolver.1.gz b/_doc/resolver.1.gz index d1343ca..599ce1d 100644 Binary files a/_doc/resolver.1.gz and b/_doc/resolver.1.gz differ diff --git a/_doc/resolver.adoc b/_doc/resolver.adoc index cee9158..9c475d9 100644 --- a/_doc/resolver.adoc +++ b/_doc/resolver.adoc @@ -112,6 +112,7 @@ caches remove :: + -- Remove the domain name from rescached caches. +If the parameter is "all", it will remove all caches. -- diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go index 0be5375..90a1686 100644 --- a/cmd/resolver/main.go +++ b/cmd/resolver/main.go @@ -163,6 +163,7 @@ caches search caches remove Remove the domain name from rescached caches. + If the parameter is "all", it will remove all caches. == Examples diff --git a/go.mod b/go.mod index 800804a..4822aa2 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ module github.com/shuLhan/rescached-go/v4 go 1.16 -require github.com/shuLhan/share v0.36.1-0.20220414184434-86c787c31de4 +require github.com/shuLhan/share v0.36.1-0.20220414192731-ceba0704c6fc //replace github.com/shuLhan/share => ../share diff --git a/go.sum b/go.sum index 5c8bbb6..1ce3cad 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/shuLhan/share v0.36.1-0.20220414184434-86c787c31de4 h1:jcfsLdh6zvuRraYyV1t7SGZ9e1x/HJIzAq35itNWh7c= -github.com/shuLhan/share v0.36.1-0.20220414184434-86c787c31de4/go.mod h1:laKGR1DNboj8+INRIC9VFYRiVEu/IIjrLurUmTHXkw0= +github.com/shuLhan/share v0.36.1-0.20220414192731-ceba0704c6fc h1:PRCQ/x8ZzOv+dlSNl3NVZgkq3rpQd4Wwz33Q73T6P2k= +github.com/shuLhan/share v0.36.1-0.20220414192731-ceba0704c6fc/go.mod h1:laKGR1DNboj8+INRIC9VFYRiVEu/IIjrLurUmTHXkw0= golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= diff --git a/httpd.go b/httpd.go index 6f4a234..7eacaa1 100644 --- a/httpd.go +++ b/httpd.go @@ -79,7 +79,7 @@ func (srv *Server) httpdRegisterEndpoints() (err error) { Path: apiCaches, RequestType: libhttp.RequestTypeQuery, ResponseType: libhttp.ResponseTypeJSON, - Call: srv.httpdAPIDeleteCaches, + Call: srv.httpdAPICachesDelete, }) if err != nil { return err @@ -287,7 +287,7 @@ func (srv *Server) apiCachesSearch(epr *libhttp.EndpointRequest) (resBody []byte return json.Marshal(&res) } -func (srv *Server) httpdAPIDeleteCaches(epr *libhttp.EndpointRequest) (resBody []byte, err error) { +func (srv *Server) httpdAPICachesDelete(epr *libhttp.EndpointRequest) (resBody []byte, err error) { var ( res = libhttp.EndpointResponse{} q = epr.HttpRequest.Form.Get(paramNameName) @@ -300,8 +300,11 @@ func (srv *Server) httpdAPIDeleteCaches(epr *libhttp.EndpointRequest) (resBody [ res.Message = "empty query 'name' parameter" return nil, &res } - - answers = srv.dns.RemoveCachesByNames([]string{q}) + if q == "all" { + answers = srv.dns.CachesClear() + } else { + answers = srv.dns.RemoveCachesByNames([]string{q}) + } res.Code = http.StatusOK res.Data = answers -- cgit v1.3