Overrides!
continuous-integration/drone/tag Build was killed Details

Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
Martyn 2020-06-28 18:36:33 +02:00
parent d534eb36cd
commit c346052895
1 changed files with 31 additions and 3 deletions

View File

@ -30,6 +30,7 @@ func RootHandler(response http.ResponseWriter, request *http.Request) {
} }
var globalQueue chan queue.QueueItem var globalQueue chan queue.QueueItem
var overrideFlag chan queue.QueueItem
func PatternHandler(response http.ResponseWriter, request *http.Request) { func PatternHandler(response http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request) vars := mux.Vars(request)
@ -50,12 +51,17 @@ func PatternHandler(response http.ResponseWriter, request *http.Request) {
} else { } else {
e.Speed = 40 e.Speed = 40
} }
if vars["override"] == "true" {
overrideFlag <- e
} else {
globalQueue <- e globalQueue <- e
}
fmt.Fprint(response, "OKAY") fmt.Fprint(response, "OKAY")
} }
func ColourHandler(response http.ResponseWriter, request *http.Request) { func ColourHandler(response http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request) vars := mux.Vars(request)
fmt.Printf("Vars : %v\n", vars)
response.Header().Add("Content-type", "text/plain") response.Header().Add("Content-type", "text/plain")
var e queue.QueueItem var e queue.QueueItem
e.Effect = "colour" e.Effect = "colour"
@ -76,6 +82,11 @@ func ColourHandler(response http.ResponseWriter, request *http.Request) {
} }
e.SeedColour = c e.SeedColour = c
globalQueue <- e globalQueue <- e
if vars["override"] == "true" {
overrideFlag <- e
} else {
globalQueue <- e
}
fmt.Fprint(response, "OKAY") fmt.Fprint(response, "OKAY")
} }
@ -108,12 +119,25 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
} }
} }
e.SecondColour = c e.SecondColour = c
if vars["override"] == "true" {
overrideFlag <- e
} else {
globalQueue <- e globalQueue <- e
}
fmt.Fprint(response, "OKAY") fmt.Fprint(response, "OKAY")
} }
func HandleHTTP(queueChannel chan queue.QueueItem, Port int) { func ResumeHandler(response http.ResponseWriter, request *http.Request) {
response.Header().Add("Content-type", "text/plain")
var e queue.QueueItem
e.Effect = "queue"
overrideFlag <- e
fmt.Fprint(response, "OKAY")
}
func HandleHTTP(queueChannel chan queue.QueueItem, Port int, overrideChannel chan queue.QueueItem) {
globalQueue = queueChannel globalQueue = queueChannel
overrideFlag = overrideChannel
r := mux.NewRouter() r := mux.NewRouter()
loggedRouter := handlers.LoggingHandler(os.Stdout, r) loggedRouter := handlers.LoggingHandler(os.Stdout, r)
r.NotFoundHandler = http.HandlerFunc(NotFoundHandler) r.NotFoundHandler = http.HandlerFunc(NotFoundHandler)
@ -123,11 +147,15 @@ func HandleHTTP(queueChannel chan queue.QueueItem, Port int) {
r.HandleFunc("/pattern/{pattern}/{duration}", PatternHandler) r.HandleFunc("/pattern/{pattern}/{duration}", PatternHandler)
r.HandleFunc("/pattern/{pattern}/{duration}/{speed}", PatternHandler) r.HandleFunc("/pattern/{pattern}/{duration}/{speed}", PatternHandler)
r.HandleFunc("/colour/{name}", ColourHandler) r.HandleFunc("/colour/{name}", ColourHandler)
r.HandleFunc("/colour/{name}/override={override}", ColourHandler)
r.HandleFunc("/colour/{name}/{duration}", ColourHandler) r.HandleFunc("/colour/{name}/{duration}", ColourHandler)
r.HandleFunc("/color/{name}", ColourHandler) r.HandleFunc("/color/{name}", ColourHandler)
r.HandleFunc("/color/{name}/override={override}", ColourHandler)
r.HandleFunc("/color/{name}/{duration}", ColourHandler) r.HandleFunc("/color/{name}/{duration}", ColourHandler)
r.HandleFunc("/fade/{namefrom}/{nameto}", FadeHandler) r.HandleFunc("/fade/{namefrom}/{nameto}", FadeHandler)
r.HandleFunc("/fade/{namefrom}/{nameto}/override={override}", FadeHandler)
r.HandleFunc("/fade/{namefrom}/{nameto}/{duration}", FadeHandler) r.HandleFunc("/fade/{namefrom}/{nameto}/{duration}", FadeHandler)
r.HandleFunc("/resumequeue", ResumeHandler)
http.Handle("/", r) http.Handle("/", r)
srv := &http.Server{ srv := &http.Server{
Handler: loggedRouter, Handler: loggedRouter,