diff --git a/cmd/circologd/http_ctl.go b/cmd/circologd/http_ctl.go index f35a0bc..75a6223 100644 --- a/cmd/circologd/http_ctl.go +++ b/cmd/circologd/http_ctl.go @@ -26,8 +26,9 @@ func togglePause(hub circolog.Hub, verbose bool) http.HandlerFunc { if verbose { log.Printf("[%s] %s - toggled pause", r.Method, r.RemoteAddr) } - hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle} - resp := <-hub.Responses + response := make(chan circolog.CommandResponse) + hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle, Response: response} + resp := <-response active := resp.Value.(bool) w.Header().Set("content-type", "application/json") enc := json.NewEncoder(w) @@ -40,8 +41,9 @@ func clearQueue(hub circolog.Hub, verbose bool) http.HandlerFunc { if verbose { log.Printf("[%s] %s - cleared queue", r.Method, r.RemoteAddr) } - hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandClear} - resp := <-hub.Responses + response := make(chan circolog.CommandResponse) + hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandClear, Response: response} + resp := <-response success := resp.Value.(bool) w.Header().Set("content-type", "application/json") enc := json.NewEncoder(w) diff --git a/cmd/circologd/main.go b/cmd/circologd/main.go index 6f269c7..09e11cc 100644 --- a/cmd/circologd/main.go +++ b/cmd/circologd/main.go @@ -108,8 +108,9 @@ func main() { select { case sig := <-interrupt: if sig == syscall.SIGUSR1 { - hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle} - resp := <-hub.Responses + response := make(chan circolog.CommandResponse) + hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle, Response: response} + resp := <-response if resp.Value.(bool) { log.Println("resumed") } else { @@ -117,8 +118,9 @@ func main() { } } if sig == syscall.SIGUSR2 { - hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandClear} - resp := <-hub.Responses + response := make(chan circolog.CommandResponse) + hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandClear, Response: response} + resp := <-response if resp.Value.(bool) { log.Println("buffer cleaned") } else { diff --git a/hub.go b/hub.go index be530e4..61e2a91 100644 --- a/hub.go +++ b/hub.go @@ -35,7 +35,8 @@ const ( // An HubFullCommand is a Command, complete with arguments type HubFullCommand struct { - Command HubCommand + Command HubCommand + Response chan CommandResponse } type CommandResponse struct { Value interface{} @@ -46,7 +47,6 @@ type Hub struct { Unregister chan Client LogMessages chan format.LogParts Commands chan HubFullCommand - Responses chan CommandResponse clients map[Client]bool circbuf *ring.Ring @@ -59,7 +59,6 @@ func NewHub(ringBufSize int) Hub { Unregister: make(chan Client), LogMessages: make(chan format.LogParts), Commands: make(chan HubFullCommand), - Responses: make(chan CommandResponse), circbuf: ring.New(ringBufSize), } } @@ -125,11 +124,11 @@ func (h *Hub) Run() { case cmd := <-h.Commands: if cmd.Command == CommandClear { h.clear() - h.Responses <- CommandResponse{Value: true} + cmd.Response <- CommandResponse{Value: true} } if cmd.Command == CommandPauseToggle { active = !active - h.Responses <- CommandResponse{Value: active} + cmd.Response <- CommandResponse{Value: active} } } }