Overrides!
continuous-integration/drone/tag Build was killed
Details
continuous-integration/drone/tag Build was killed
Details
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
parent
d534eb36cd
commit
c346052895
|
@ -30,6 +30,7 @@ func RootHandler(response http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
|
||||
var globalQueue chan queue.QueueItem
|
||||
var overrideFlag chan queue.QueueItem
|
||||
|
||||
func PatternHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
|
@ -50,12 +51,17 @@ func PatternHandler(response http.ResponseWriter, request *http.Request) {
|
|||
} else {
|
||||
e.Speed = 40
|
||||
}
|
||||
if vars["override"] == "true" {
|
||||
overrideFlag <- e
|
||||
} else {
|
||||
globalQueue <- e
|
||||
}
|
||||
fmt.Fprint(response, "OKAY")
|
||||
}
|
||||
|
||||
func ColourHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
fmt.Printf("Vars : %v\n", vars)
|
||||
response.Header().Add("Content-type", "text/plain")
|
||||
var e queue.QueueItem
|
||||
e.Effect = "colour"
|
||||
|
@ -76,6 +82,11 @@ func ColourHandler(response http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
e.SeedColour = c
|
||||
globalQueue <- e
|
||||
if vars["override"] == "true" {
|
||||
overrideFlag <- e
|
||||
} else {
|
||||
globalQueue <- e
|
||||
}
|
||||
fmt.Fprint(response, "OKAY")
|
||||
}
|
||||
|
||||
|
@ -108,12 +119,25 @@ func FadeHandler(response http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
}
|
||||
e.SecondColour = c
|
||||
if vars["override"] == "true" {
|
||||
overrideFlag <- e
|
||||
} else {
|
||||
globalQueue <- e
|
||||
}
|
||||
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
|
||||
overrideFlag = overrideChannel
|
||||
r := mux.NewRouter()
|
||||
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
|
||||
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}/{speed}", PatternHandler)
|
||||
r.HandleFunc("/colour/{name}", ColourHandler)
|
||||
r.HandleFunc("/colour/{name}/override={override}", ColourHandler)
|
||||
r.HandleFunc("/colour/{name}/{duration}", ColourHandler)
|
||||
r.HandleFunc("/color/{name}", ColourHandler)
|
||||
r.HandleFunc("/color/{name}/override={override}", ColourHandler)
|
||||
r.HandleFunc("/color/{name}/{duration}", ColourHandler)
|
||||
r.HandleFunc("/fade/{namefrom}/{nameto}", FadeHandler)
|
||||
r.HandleFunc("/fade/{namefrom}/{nameto}/override={override}", FadeHandler)
|
||||
r.HandleFunc("/fade/{namefrom}/{nameto}/{duration}", FadeHandler)
|
||||
r.HandleFunc("/resumequeue", ResumeHandler)
|
||||
http.Handle("/", r)
|
||||
srv := &http.Server{
|
||||
Handler: loggedRouter,
|
||||
|
|
Loading…
Reference in New Issue