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.

48 lines
1.2 KiB
Go

package router
import (
"github.com/exhibition-main/internal/middleware"
"github.com/exhibition-main/pkg/service"
"github.com/exhibition-main/pkg/service/common"
"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))
auth := r.Group("")
auth.Use(middleware.JWTAuthMiddleware())
// 上传
upload := auth.Group("upload")
{
upload.POST("img", common.UploadImg)
}
registerAuth := auth.Group("register")
{
registerAuth.POST("register_record_list", service.RegisterList)
registerAuth.POST("check_by_phone", service.CheckByPhone)
registerAuth.POST("save_register_info", service.SaveRegister)
registerAuth.POST("export_register", service.ExportRegister)
}
//静态文件
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
}