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 /httpd.go | |
| 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.
Diffstat (limited to 'httpd.go')
| -rw-r--r-- | httpd.go | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -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 |
