-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (36 loc) · 897 Bytes
/
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
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
)
var (
Connects map[string]*Connect
Config Configuration
)
func init() {
Connects = make(map[string]*Connect, 10)
Config = loadConf(SYSTEM_PATH)
// `kill -USR1 pid` to reload config
go reloadConf(SYSTEM_PATH)
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.ServeFiles("/static/*filepath", http.Dir("static"))
router.POST("/api/sign/exec", apiSignExec)
router.GET("/ws/terminal/:token", wsTerminal)
fmt.Printf("Listen %s ...\n", Config.Listen)
log.Fatal(http.ListenAndServe(Config.Listen, router))
}
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
if Config.Quick_Start == false {
w.WriteHeader(404)
w.Write([]byte("Not Found!"))
return
}
t, _ := template.ParseFiles("static/index.html")
t.Execute(w, Config)
}