|
@@ -6,28 +6,46 @@ import (
|
|
|
"log"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
+ "time"
|
|
|
|
|
|
fractal "git.lattuga.net/blallo/gotools/formatting"
|
|
|
"git.lattuga.net/boyska/circolog"
|
|
|
"github.com/gorilla/mux"
|
|
|
)
|
|
|
|
|
|
-func setupHTTPCtl(hub circolog.Hub, verbose bool) *mux.Router {
|
|
|
+func setupHTTPCtl(hub circolog.Hub, verbose, debug bool) *mux.Router {
|
|
|
m := mux.NewRouter()
|
|
|
- m.HandleFunc("/pause/toggle", togglePause(hub, verbose)).Methods("POST")
|
|
|
+ m.HandleFunc("/pause/toggle", togglePause(hub, verbose, debug)).Methods("POST")
|
|
|
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 togglePause(hub circolog.Hub, verbose bool) http.HandlerFunc {
|
|
|
+func togglePause(hub circolog.Hub, verbose, debug bool) http.HandlerFunc {
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
if verbose {
|
|
|
log.Printf("[%s] %s - toggled pause", r.Method, r.RemoteAddr)
|
|
|
}
|
|
|
+ r.ParseForm()
|
|
|
+ waitTimePar := r.FormValue("waitTime")
|
|
|
+ var waitTime time.Duration
|
|
|
+ var err error
|
|
|
+ if waitTimePar != "" {
|
|
|
+ waitTime, err = time.ParseDuration(waitTimePar)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("waitTime not understood:", waitTimePar)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if debug {
|
|
|
+ fmt.Println("[DEBUG] waitTime:", waitTime)
|
|
|
+ }
|
|
|
response := make(chan circolog.CommandResponse)
|
|
|
- hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle, Response: response}
|
|
|
+ hub.Commands <- circolog.HubFullCommand{
|
|
|
+ Command: circolog.CommandPauseToggle,
|
|
|
+ Response: response,
|
|
|
+ Parameters: map[string]interface{}{"waitTime": waitTime},
|
|
|
+ }
|
|
|
resp := <-response
|
|
|
active := resp.Value.(bool)
|
|
|
w.Header().Set("content-type", "application/json")
|