You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB
Go

8 months ago
package router
import (
"github.com/exhibition-main/internal/middleware"
"net/http"
"github.com/gin-contrib/gzip"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
)
// 路由配置
func NewRouter() *gin.Engine {
//使用默认gin路由
r := gin.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression))
//加入日志中间件,跨域中间件
r.Use(middleware.NewLogger(), middleware.Cors(), middleware.GinRecovery(true))
//noAuth := r.Group("")
auth := r.Group("")
auth.Use(middleware.JWTAuthMiddleware())
//userAuth := auth.Group("user")
//{
// userAuth.POST("info", api.UserInfo)
// userAuth.POST("tickets", api.Tickets)
// userAuth.POST("login-out", api.LoginOut)
// userAuth.POST("destroy", api.Destroy)
//}
//userNoAuth := noAuth.Group("user")
//{
// userNoAuth.POST("login", api.Login)
//}
//goodsAuth := auth.Group("goods")
//{
// goodsAuth.POST("drink-list", api.DrinkList)
// goodsAuth.POST("ticket-list", api.TickerList)
// goodsAuth.POST("set-meal-list", api.SetMealList)
//}
//
//orderAuth := auth.Group("order")
//{
// orderAuth.POST("buy-goods", api.BuyGoods)
// orderAuth.POST("buy-tickets", api.BuyTicket)
// orderAuth.POST("buy-balance", api.BuyBalance)
// orderAuth.POST("buy-set-meal", api.BuySetMeal)
// orderAuth.POST("history-goods", api.HistoryGoods)
// orderAuth.POST("history-tickets", api.HistoryTickets)
// orderAuth.POST("history-balance", api.HistoryBalance)
//}
//
//orderNoAuth := noAuth.Group("order")
//{
// orderNoAuth.POST("wx_callback", api.WxCallback)
// orderAuth.POST("order-data-h5", api.OrderDataH5)
// orderAuth.POST("update-h5-order", api.UpdateH5Order)
//}
//
//miniNoAuth := noAuth.Group("mini")
//{
// miniNoAuth.POST("url-scheme", api.UrlScheme)
//}
//静态文件
r.StaticFS("/static", http.Dir("./runtime"))
r.NoRoute(func(c *gin.Context) {
c.JSON(http.StatusNotFound, gin.H{
"status": 1,
"msg": "不存在的路由",
})
})
pprof.Register(r)
return r
}