47 lines
1.1 KiB
Go
47 lines
1.1 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.RegisterRecordList)
|
|
registerAuth.POST("check_by_phone", service.CheckPhone)
|
|
registerAuth.POST("save_register_info", service.SaveRegisterRecord)
|
|
}
|
|
|
|
//静态文件
|
|
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
|
|
}
|