-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
57 lines (45 loc) · 1.15 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
package main
import (
"encoding/json"
"log"
"net/http"
"time"
rcon "github.com/forewing/csgo-rcon"
"github.com/gin-gonic/gin"
)
var (
client *rcon.Client
)
func main() {
conf, err := json.MarshalIndent(flags, "", " ")
if err != nil {
panic(err)
}
log.Println(string(conf))
client = rcon.New(*flags.Address, *flags.Password, time.Duration(*flags.Timeout*float64(time.Second)))
prepareFS(*flags.Debug)
if *flags.Debug {
} else {
gin.SetMode(gin.ReleaseMode)
}
checkPreset()
router := gin.Default()
// Set HTML handler
router.SetHTMLTemplate(mustLoadTemplate())
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{})
})
router.StaticFS("/statics", http.FS(statics))
router.GET("/preset.json", getPreset)
router.GET("/api/connect", getConnect)
routerExec := router.Group("/api/exec")
if len(*flags.BasicAuthUsername) > 0 {
routerExec = router.Group("/api/exec", gin.BasicAuth(gin.Accounts{
*flags.BasicAuthUsername: *flags.BasicAuthPassword,
}))
}
routerExec.GET("/", getExec)
routerExec.POST("/", postExec)
log.Println("Listening on", "http://"+*flags.Bind)
log.Fatalln(router.Run(*flags.Bind))
}