package init_serve

import (
	"github.com/gin-gonic/gin"
	"github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	_ "hongze/hongze_yb/docs"
	"hongze/hongze_yb/global"
	"hongze/hongze_yb/middleware"
	"hongze/hongze_yb/routers"
)

// InitRouter 初始化路由
func InitRouter() (r *gin.Engine) {
	//设置
	gin.SetMode(global.CONFIG.Serve.RunMode)
	// 1.创建路由
	r = gin.Default()
	r.Use(middleware.Cors())
	//r.Use(gin.Recovery())
	r.Use(middleware.Recover())

	//swagger界面访问地址
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	// 2.绑定路由规则，执行的函数
	// gin.Context，封装了request和response
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	routers.InitTest(r)
	// 微信相关路由
	routers.InitWechat(r)
	// 活动相关路由
	routers.InitActivity(r)
	// 用户接口
	routers.InitUser(r)
	// 公共接口
	routers.InitPublic(r)
	// 报告接口
	routers.InitResearchReport(r)
	// 图库相关路由
	routers.InitChart(r)

	return
}
