forked from boyska/circolog
boyska
1b08df0ce0
also there is some refactoring on circologd: connection handling, closing, etc. Not as much as needed, though: shutdown is still unclean, and websocket clean shutdown is not tested
26 lines
660 B
Go
26 lines
660 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"git.lattuga.net/boyska/circolog"
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func setupHTTPCtl(hub circolog.Hub) *mux.Router {
|
|
mux := mux.NewRouter()
|
|
mux.HandleFunc("/pause/toggle", togglePause(hub)).Methods("POST")
|
|
return mux
|
|
}
|
|
|
|
func togglePause(hub circolog.Hub) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle}
|
|
resp := <-hub.Responses
|
|
active := resp.Value.(bool)
|
|
w.Header().Set("content-type", "application/json")
|
|
enc := json.NewEncoder(w)
|
|
enc.Encode(map[string]interface{}{"paused": !active})
|
|
}
|
|
}
|