-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
48 lines (41 loc) · 1.25 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
package main
import (
"log"
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
"github.com/nodebreaker0-0/gin-oauth-test/handlers"
"github.com/nodebreaker0-0/gin-oauth-test/middleware"
)
func main() {
router := gin.Default()
token, err := handlers.RandToken(64)
if err != nil {
log.Fatal("unable to generate random token: ", err)
}
store := sessions.NewCookieStore([]byte(token))
store.Options(sessions.Options{
Path: "/",
MaxAge: 600,
HttpOnly: true,
Secure: true,
})
router.Use(gin.Logger())
router.Use(gin.Recovery())
router.Use(sessions.Sessions("adminsession", store))
router.Static("/css", "./static/css")
router.Static("/img", "./static/img")
router.LoadHTMLGlob("templates/*")
//router.GET("/", handlers.IndexHandler)
router.GET("/login", handlers.LoginHandler)
router.GET("/auth", handlers.AuthHandler)
router.Use(middleware.AuthorizeRequest())
{
router.Use(static.Serve("/", static.LocalFile("./all-in-one-admin/build", true)))
router.GET("/GetnodeStatus", handlers.GetnodeStatusHandler)
router.GET("/GetvalidatorSignInfo", handlers.GetvalidatorSignInfo)
}
if err := router.RunTLS(":443", "./server.crt", "./server.key"); err != nil {
log.Fatal(err)
}
}