package router import ( "applet/app/cfg" "applet/app/hdl" internalHdl "applet/app/hdl/zhimeng_internal" platformHdl "applet/app/hdl/zhimeng_platform" "applet/app/mw" "github.com/gin-gonic/gin" ) // 初始化路由 func Init() *gin.Engine { // debug, release, test 项目阶段 mode := "release" if cfg.Debug { mode = "debug" } gin.SetMode(mode) //创建一个新的启动器 r := gin.New() r.Use(mw.ChangeHeader) // 是否打印访问日志, 在非正式环境都打印 if mode != "release" { r.Use(gin.Logger()) } r.Use(gin.Recovery()) // r.Use(mw.Limiter) //r.LoadHTMLGlob("static/html/*") r.GET("/favicon.ico", func(c *gin.Context) { c.Status(204) }) r.NoRoute(func(c *gin.Context) { c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}}) }) r.NoMethod(func(c *gin.Context) { c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}}) }) r.Use(mw.Cors) routeInternal(r.Group("/api/internal")) routeZhimeng(r.Group("/api/admin")) return r } func routeInternal(r *gin.RouterGroup) { r.Use(mw.DB) // 以下接口需要用到数据库 { r.POST("/playlet_order", internalHdl.GetPlayletOrder) r.POST("/hw_order", internalHdl.GetHwOrder) r.POST("/playlet_short_link", internalHdl.GetShortLink) } r.Use(mw.Checker) // 以下接口需要检查Header: platform { } r.Use(mw.Auth) // 以下接口需要JWT验证 { } } func routeZhimeng(r *gin.RouterGroup) { r.POST("kuaishou/auth", hdl.KuaishouAuth) r.GET("/test", hdl.Order) r.GET("/cinema", hdl.Cinema) r.GET("/task", hdl.TikTokTask) r.POST("/bihai_file_new", hdl.BihaiFile) r.GET("/bihai_add", hdl.BihaiAdds) r.GET("/bihai_story_add", hdl.BihaiStoryAdd) r.GET("/beiwo_story_add", hdl.BeiwoStoryAdd) r.GET("/kujiang_add", hdl.KujiangAdd) r.POST("/file_new", hdl.File) r.POST("/file_new1", hdl.FileNew) r.POST("/file_old", hdl.FileTwo) r.POST("/file_old1", hdl.FileTwoNew) r.POST("/file_second", hdl.FileSecond) r.POST("/file_down", hdl.FileDown) r.POST("/file_down1", hdl.FileDownNew) r.GET("/authorizationCode", hdl.GetAuthorizationCode) r.GET("/token", hdl.GetToken) r.POST("/rToken", hdl.RefreshToken) r.POST("/file/upload/token", mw.InitReqValidator, hdl.ImgReqUpload) // 文件上传获取七牛云上传token r.POST("/file/upload/callback", hdl.FileImgCallback) // 文件上传回调 r.Use(mw.AuthJWT, mw.RequestCache) // 以下接口需要JWT验证 { r.POST("/order_list", platformHdl.OrderList) r.POST("/order_output", platformHdl.OrderOutput) r.POST("/:pvd/order_list", platformHdl.NewOrderList) r.POST("/:pvd/order_output", platformHdl.NewOrderOutput) //r.POST("/hw_order_list", platformHdl.HwOrderList) //r.POST("/hw_order_output", platformHdl.HwOrderOutput) //r.POST("/guide_order_list", platformHdl.GuideOrderList) //r.POST("/guide_order_output", platformHdl.GuideOrderOutput) r.POST("/withdrawal_income", platformHdl.WithdrawalIncome) r.POST("/withdrawal_bind_alipay", platformHdl.WithdrawalBindAlipay) r.POST("/withdrawal_list", platformHdl.WithdrawalList) r.POST("/withdrawal_doing", platformHdl.WithdrawalDoing) r.POST("/withdrawal_output", platformHdl.WithdrawalOutput) r.POST("/withdrawal_invoice_img", platformHdl.WithdrawalInvoiceImg) } }