get status
This commit is contained in:
parent
518b8a5588
commit
20269bf94e
2 changed files with 24 additions and 3 deletions
|
@ -16,12 +16,27 @@ import (
|
||||||
func setupHTTPCtl(hub circolog.Hub, verbose, debug bool) *mux.Router {
|
func setupHTTPCtl(hub circolog.Hub, verbose, debug bool) *mux.Router {
|
||||||
m := mux.NewRouter()
|
m := mux.NewRouter()
|
||||||
m.HandleFunc("/pause/toggle", togglePause(hub, verbose, debug)).Methods("POST")
|
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("/logs/clear", clearQueue(hub, verbose)).Methods("POST")
|
||||||
m.HandleFunc("/help", printHelp(verbose)).Methods("GET")
|
m.HandleFunc("/help", printHelp(verbose)).Methods("GET")
|
||||||
m.HandleFunc("/echo", echo(verbose)).Methods("GET")
|
m.HandleFunc("/echo", echo(verbose)).Methods("GET")
|
||||||
return m
|
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 {
|
func togglePause(hub circolog.Hub, verbose, debug bool) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if verbose {
|
if verbose {
|
||||||
|
|
12
hub.go
12
hub.go
|
@ -33,6 +33,7 @@ type HubCommand int
|
||||||
const (
|
const (
|
||||||
CommandClear = iota
|
CommandClear = iota
|
||||||
CommandPauseToggle = iota
|
CommandPauseToggle = iota
|
||||||
|
CommandStatus = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
// An HubFullCommand is a Command, complete with arguments
|
// An HubFullCommand is a Command, complete with arguments
|
||||||
|
@ -125,17 +126,22 @@ func (h *Hub) Run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case cmd := <-h.Commands:
|
case cmd := <-h.Commands:
|
||||||
if cmd.Command == CommandClear {
|
switch cmd.Command {
|
||||||
|
case CommandClear:
|
||||||
h.clear()
|
h.clear()
|
||||||
cmd.Response <- CommandResponse{Value: true}
|
cmd.Response <- CommandResponse{Value: true}
|
||||||
}
|
case CommandPauseToggle:
|
||||||
if cmd.Command == CommandPauseToggle {
|
|
||||||
togglePause(cmd.Parameters["waitTime"].(time.Duration), &active)
|
togglePause(cmd.Parameters["waitTime"].(time.Duration), &active)
|
||||||
if active {
|
if active {
|
||||||
fmt.Print("un")
|
fmt.Print("un")
|
||||||
}
|
}
|
||||||
fmt.Println("paused")
|
fmt.Println("paused")
|
||||||
cmd.Response <- CommandResponse{Value: active}
|
cmd.Response <- CommandResponse{Value: active}
|
||||||
|
case CommandStatus:
|
||||||
|
cmd.Response <- CommandResponse{Value: map[string]interface{}{
|
||||||
|
"size": h.circbuf.Len(),
|
||||||
|
"paused": !active,
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue