diff --git a/cmd/circologd/http.go b/cmd/circologd/http.go index 7962d8d..5e58bc9 100644 --- a/cmd/circologd/http.go +++ b/cmd/circologd/http.go @@ -13,6 +13,7 @@ import ( "gopkg.in/mcuadros/go-syslog.v2/format" ) +// TODO: return a server func setupHTTP(hub circolog.Hub) { http.HandleFunc("/", getHTTPHandler(hub)) http.HandleFunc("/ws", getWSHandler(hub)) diff --git a/cmd/circologd/main.go b/cmd/circologd/main.go index aed1266..e3d2b8d 100644 --- a/cmd/circologd/main.go +++ b/cmd/circologd/main.go @@ -89,12 +89,18 @@ func main() { select { case sig := <-interrupt: if sig == syscall.SIGHUP { - log.Println("Clearing queue") hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandClear} + <-hub.Responses + log.Println("Queue cleared") } if sig == syscall.SIGUSR1 { - log.Println("Pause/resume") hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle} + resp := <-hub.Responses + if resp.Value.(bool) { + log.Println("resumed") + } else { + log.Println("paused") + } } if sig == syscall.SIGTERM || sig == syscall.SIGINT { log.Println("Quitting because of signal", sig) diff --git a/hub.go b/hub.go index f4c746b..639612f 100644 --- a/hub.go +++ b/hub.go @@ -37,12 +37,16 @@ const ( type HubFullCommand struct { Command HubCommand } +type CommandResponse struct { + Value interface{} +} type Hub struct { Register chan Client Unregister chan Client LogMessages chan format.LogParts Commands chan HubFullCommand + Responses chan CommandResponse clients map[Client]bool circbuf *ring.Ring @@ -55,6 +59,7 @@ 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), } } @@ -120,9 +125,11 @@ func (h *Hub) Run() { case cmd := <-h.Commands: if cmd.Command == CommandClear { h.clear() + h.Responses <- CommandResponse{Value: true} } if cmd.Command == CommandPauseToggle { active = !active + h.Responses <- CommandResponse{Value: active} } } }