-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.go
36 lines (29 loc) · 930 Bytes
/
router.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
package main
import (
"github.com/forseason/env"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
)
var store redis.Store
// 这个函数用于注册路由
func (this *app) initRouter() {
r := this.r
r.Use(this.middleware.CORS())
// 初始化session组件
var err error
store, err = redis.NewStore(30, "tcp", env.Get("REDIS_HOST", ""), env.Get("REDIS_PASSWORD", ""), []byte("__100steps__100steps__100steps__"))
if err != nil {
panic(err)
}
r.Use(sessions.Sessions(env.Get("SESSION_NAME", "gin-layout"), store))
r.GET("/", func(ctx *gin.Context) {
ctx.String(200, "ok")
})
api := r.Group("/api")
api.GET("/user", this.userController.Index)
api.POST("/user", this.userController.Register)
api.POST("/session", this.userController.Login)
authedApi := api.Group("", this.middleware.Authentication())
authedApi.GET("/me", this.userController.ShowMe)
}