mtfosbot/router/routes/routes.go

47 lines
836 B
Go
Raw Normal View History

2018-08-14 09:25:34 +00:00
package routes
import (
2018-09-02 01:15:27 +00:00
"log"
"git.trj.tw/golang/mtfosbot/module/context"
"git.trj.tw/golang/mtfosbot/router/api"
2018-08-14 09:25:34 +00:00
"github.com/gin-contrib/cors"
2018-09-02 01:15:27 +00:00
"github.com/gin-gonic/contrib/sessions"
2018-08-14 09:25:34 +00:00
"github.com/gin-gonic/gin"
)
// NewServ - create new gin server
func NewServ() *gin.Engine {
r := gin.New()
2018-09-02 01:15:27 +00:00
store, err := sessions.NewRedisStore(10, "tcp", "localhost:6379", "")
if err != nil {
log.Fatal(err)
}
2018-08-14 09:25:34 +00:00
// access log
r.Use(gin.Logger())
// error catch
r.Use(gin.Recovery())
// enable cors
r.Use(cors.Default())
2018-09-02 01:15:27 +00:00
// session
2018-09-02 03:24:40 +00:00
r.Use(sessions.Sessions("ginsess", store))
2018-09-02 01:15:27 +00:00
2018-08-14 09:25:34 +00:00
return r
}
// SetRoutes - set routes
func SetRoutes(r *gin.Engine) {
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "ok",
})
})
2018-09-02 01:15:27 +00:00
apiGroup := r.Group("/api")
{
apiGroup.POST("/login", context.PatchCtx(api.UserLogin))
}
2018-08-14 09:25:34 +00:00
}