-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (44 loc) · 1.49 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 (
"fmt"
"log"
"github.com/gin-gonic/gin"
"github.com/gar-r/ppnext/config"
"github.com/gar-r/ppnext/controller"
)
func main() {
r := initRouter()
scheduleBackgroundCleanup()
addr := fmt.Sprintf(":%d", config.Port)
log.Fatal(r.Run(addr))
}
func initRouter() *gin.Engine {
r := gin.Default()
r.StaticFile("/favicon.ico", "./assets/favicon.ico")
r.StaticFile("/scripts.js", "./assets/scripts.js")
r.StaticFile("/tooltip.js", "./assets/tooltip.js")
r.StaticFile("/styles.css", "./assets/styles.css")
r.StaticFile("/materialize.min.css", "./assets/materialize.min.css")
r.StaticFile("/materialize.min.css.map", "./assets/materialize.min.css.map")
r.StaticFile("/materialize.min.js", "./assets/materialize.min.js")
r.LoadHTMLGlob("templates/*")
r.Use(controller.Auth())
// public routes
r.GET("/", controller.ShowLogin)
r.GET("/login", controller.ShowLogin)
r.POST("/login", controller.HandleLogin)
r.GET("/logout", controller.HandleLogout)
// protected routes
prot := r.Group("/rooms", controller.Prot())
prot.GET("/:room", controller.DisplayRoom)
api := r.Group("/rooms", controller.Api())
api.GET("/:room/userlist", controller.UserList)
api.GET("/:room/results", controller.Results)
api.GET("/:room/events", controller.GetEvents)
active := api.Group("/", controller.Active())
active.POST("/:room/vote", controller.AcceptVote)
active.POST("/:room/reveal", controller.Reveal)
active.POST("/:room/reset", controller.ResetRoom)
_ = r.SetTrustedProxies(nil)
return r
}