forked from yottamusic/DeviceConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (49 loc) · 1.58 KB
/
main.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"log"
"net/http"
"github.com/yottamusic/DeviceConfig/devapi"
)
func wifiModeHandler(w http.ResponseWriter, r *http.Request) {
devapi.WifiModeHandler(w, r)
}
func wifiListHandler(w http.ResponseWriter, r *http.Request) {
devapi.WifiSSIDHandler(w, r)
}
func wifiConnectionHandler(w http.ResponseWriter, r *http.Request) {
devapi.WifiConnectionHandler(w, r)
}
func speakerListHandler(w http.ResponseWriter, r *http.Request) {
devapi.SpeakerListHandler(w, r)
}
func speakerSelectHandler(w http.ResponseWriter, r *http.Request) {
devapi.SpeakerSelectHandler(w, r)
}
func speakerConfigHandler(w http.ResponseWriter, r *http.Request) {
devapi.SpeakerConfigHandler(w, r)
}
func setupRoutes() {
// Handle Configuration Requests for Wi-FI and Speakers
http.HandleFunc("/wifi/api/v1/mode", wifiModeHandler)
http.HandleFunc("/wifi/api/v1/list", wifiListHandler)
http.HandleFunc("/wifi/api/v1/connect", wifiConnectionHandler)
http.HandleFunc("/speakers/api/v1/list", speakerListHandler)
http.HandleFunc("/speakers/api/v1/select", speakerSelectHandler)
http.HandleFunc("/speakers/api/v1/config", speakerConfigHandler)
// Handle Any Request
port := flag.String("p", "80", "Port to Serve UI on")
directory := flag.String("d", "./httpdocs", "Directory of Webpages to Serve")
flag.Parse()
fileServer := http.FileServer(http.Dir(*directory))
http.Handle("/", fileServer)
log.Printf("Serving APIs and %s on HTTP port: %s\n", *directory, *port)
err := http.ListenAndServe(":"+*port, nil)
if err != nil {
panic(err)
}
log.Fatal(err)
}
func main() {
setupRoutes()
}