-
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) · 900 Bytes
/
Copy pathmain.go
File metadata and controls
53 lines (42 loc) · 900 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("Usage: controlbox <port>")
fmt.Println()
fmt.Println("Certificate configuration via .env file:")
fmt.Println(" CERT_PEM + KEY_PEM inline PEM content")
fmt.Println(" (auto-generated and persisted on first run if absent)")
}
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()
os.Exit(1)
}
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))
}