-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (26 loc) · 707 Bytes
/
main.go
File metadata and controls
37 lines (26 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"flag"
"log"
"net/http"
)
var (
address = flag.String("addr", ":2000", "Address to bind on")
)
func main() {
flag.Parse()
lights := createController()
log.Println("Started light controller")
go lights.process()
defer lights.cleanup()
http.HandleFunc("/button/api/flash_light", func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
if request.Method != http.MethodPost {
http.Error(writer, "405 method not allowed", http.StatusMethodNotAllowed)
return
}
lights.controlChannel <- true
})
log.Printf("Starting HTTP server on %s\n", *address)
log.Fatal(http.ListenAndServe(*address, nil))
}