diff options
| author | Shulhan <ms@kilabit.info> | 2022-04-15 02:56:59 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-04-15 02:56:59 +0700 |
| commit | a33c4f7e3c9bf4b9c394a0be426b4a6740382aee (patch) | |
| tree | e5f66c8ac80a76f56263467d1aac3e199ddf7907 | |
| parent | 143087b8edc9fcfbf93dccf213c569797b1eea73 (diff) | |
| download | rescached-a33c4f7e3c9bf4b9c394a0be426b4a6740382aee.tar.xz | |
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.
| -rw-r--r-- | _doc/resolver.1.gz | bin | 2125 -> 2143 bytes | |||
| -rw-r--r-- | _doc/resolver.adoc | 1 | ||||
| -rw-r--r-- | cmd/resolver/main.go | 1 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | go.sum | 4 | ||||
| -rw-r--r-- | httpd.go | 11 |
6 files changed, 12 insertions, 7 deletions
diff --git a/_doc/resolver.1.gz b/_doc/resolver.1.gz Binary files differindex d1343ca..599ce1d 100644 --- a/_doc/resolver.1.gz +++ b/_doc/resolver.1.gz 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 <string>:: + -- 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 <string> caches remove <string> Remove the domain name from rescached caches. + If the parameter is "all", it will remove all caches. == Examples @@ -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 @@ -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= @@ -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 |
