-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (42 loc) · 835 Bytes
/
main.go
File metadata and controls
53 lines (42 loc) · 835 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
_ "github.com/joho/godotenv/autoload"
)
var remoteSki string
var frontend WebsocketClient
// main app
func usage() {
fmt.Println("First Run:")
fmt.Println(" go controlbox <serverport>")
fmt.Println()
fmt.Println("General Usage:")
fmt.Println(" go controlbox <serverport> <crtfile> <keyfile>")
}
func setupRoutes(h *controlbox) {
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
serveWs(h, w, r)
})
}
func main() {
if len(os.Args) < 2 {
usage()
return
}
srv := new(controlbox)
srv.run()
setupRoutes(srv)
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
go func() {
<-sig
os.Exit(0)
}()
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(httpdPort), nil))
}