From eb66cb43077ac2b016689116900200fbe689dac0 Mon Sep 17 00:00:00 2001 From: boyska Date: Sun, 11 Nov 2018 19:58:49 +0100 Subject: [PATCH] clear logs on contrl socket --- cmd/circologd/http_ctl.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/circologd/http_ctl.go b/cmd/circologd/http_ctl.go index 554869b..cde8538 100644 --- a/cmd/circologd/http_ctl.go +++ b/cmd/circologd/http_ctl.go @@ -11,6 +11,7 @@ import ( func setupHTTPCtl(hub circolog.Hub) *mux.Router { mux := mux.NewRouter() mux.HandleFunc("/pause/toggle", togglePause(hub)).Methods("POST") + mux.HandleFunc("/logs/clear", clearQueue(hub)).Methods("POST") return mux } @@ -24,3 +25,14 @@ func togglePause(hub circolog.Hub) http.HandlerFunc { enc.Encode(map[string]interface{}{"paused": !active}) } } + +func clearQueue(hub circolog.Hub) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandClear} + resp := <-hub.Responses + success := resp.Value.(bool) + w.Header().Set("content-type", "application/json") + enc := json.NewEncoder(w) + enc.Encode(map[string]interface{}{"success": success}) + } +}