|
@@ -16,12 +16,27 @@ 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("/status", getStatus(hub, verbose, debug)).Methods("GET")
|
|
|
m.HandleFunc("/logs/clear", clearQueue(hub, verbose)).Methods("POST")
|
|
|
m.HandleFunc("/help", printHelp(verbose)).Methods("GET")
|
|
|
m.HandleFunc("/echo", echo(verbose)).Methods("GET")
|
|
|
return m
|
|
|
}
|
|
|
|
|
|
+func getStatus(hub circolog.Hub, verbose, debug bool) http.HandlerFunc {
|
|
|
+ return func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ response := make(chan circolog.CommandResponse)
|
|
|
+ hub.Commands <- circolog.HubFullCommand{
|
|
|
+ Command: circolog.CommandStatus,
|
|
|
+ Response: response,
|
|
|
+ }
|
|
|
+ resp := <-response
|
|
|
+ w.Header().Set("content-type", "application/json")
|
|
|
+ enc := json.NewEncoder(w)
|
|
|
+ enc.Encode(map[string]interface{}{"status": resp.Value})
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func togglePause(hub circolog.Hub, verbose, debug bool) http.HandlerFunc {
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
if verbose {
|