|
@@ -16,6 +16,7 @@ import (
|
|
|
func setupHTTPCtl(hub circolog.Hub, verbose, debug bool) *mux.Router {
|
|
|
m := mux.NewRouter()
|
|
|
m.HandleFunc("/pause/toggle", togglePause(hub, verbose, debug)).Methods("POST")
|
|
|
+ m.HandleFunc("/filter", setFilter(hub, verbose, debug)).Methods("POST")
|
|
|
m.HandleFunc("/status", getStatus(hub, verbose, debug)).Methods("GET")
|
|
|
m.HandleFunc("/logs/clear", clearQueue(hub, verbose)).Methods("POST")
|
|
|
m.HandleFunc("/help", printHelp(verbose)).Methods("GET")
|
|
@@ -71,6 +72,26 @@ func togglePause(hub circolog.Hub, verbose, debug bool) http.HandlerFunc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func setFilter(hub circolog.Hub, verbose, debug bool) http.HandlerFunc {
|
|
|
+ return func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ r.ParseForm()
|
|
|
+ where := r.FormValue("where")
|
|
|
+ response := make(chan circolog.CommandResponse)
|
|
|
+ hub.Commands <- circolog.HubFullCommand{
|
|
|
+ Command: circolog.CommandNewFilter,
|
|
|
+ Response: response,
|
|
|
+ Parameters: map[string]interface{}{"where": where},
|
|
|
+ }
|
|
|
+ resp := <-response
|
|
|
+ if !resp.Value.(map[string]interface{})["success"].(bool) {
|
|
|
+ w.WriteHeader(400)
|
|
|
+ }
|
|
|
+ w.Header().Set("content-type", "application/json")
|
|
|
+ enc := json.NewEncoder(w)
|
|
|
+ enc.Encode(resp.Value)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func clearQueue(hub circolog.Hub, verbose bool) http.HandlerFunc {
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
if verbose {
|