aboutsummaryrefslogtreecommitdiff
path: root/httpd.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-04-15 02:56:59 +0700
committerShulhan <ms@kilabit.info>2022-04-15 02:56:59 +0700
commita33c4f7e3c9bf4b9c394a0be426b4a6740382aee (patch)
treee5f66c8ac80a76f56263467d1aac3e199ddf7907 /httpd.go
parent143087b8edc9fcfbf93dccf213c569797b1eea73 (diff)
downloadrescached-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.go11
1 files changed, 7 insertions, 4 deletions
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