-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
48 lines (38 loc) · 967 Bytes
/
routes.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 app
import (
"encoding/gob"
"fmt"
"net/http"
"github.com/gin-contrib/logger"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
)
// LoadRoutes .
func (app Application) LoadRoutes(r *gin.Engine) error {
// logger
r.Use(logger.SetLogger())
// auth
gob.Register(map[string]interface{}{})
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("auth-session", store))
// static
r.StaticFS("/public/static", http.Dir(fmt.Sprintf("%s/%s", app.path, "static")))
// index
r.GET("/", app.Index)
api := r.Group("/api")
{
api.GET("/add", app.Add)
}
page := r.Group("/page", app.IsAuthenticated)
{
page.GET("/list", app.List)
page.GET("/setup", app.Setup)
page.GET("/dashboard", app.Dashboard)
page.GET("/export", app.Export)
}
r.GET("/login", Login(app.authenticator))
r.GET("/callback", Callback(app.authenticator))
r.GET("/logout", app.Logout)
return nil
}