package router

import (
	"github.com/gin-gonic/gin"
	"iot_manager_service/app/middleware"
	user "iot_manager_service/app/user/controller"
	"iot_manager_service/config"
	"iot_manager_service/util/logger"
)

func InitRouter(engine *gin.Engine) {
	// 跨域处理
	engine.Use(middleware.Cors())
	// 校验token令牌
	engine.Use(middleware.AuthMiddleware())

	engine.Use(gin.Recovery())
	if config.Instance().Logger.Switch == 1 {
		engine.Use(logger.LogToFile())
	}
	engine.Use(logger.Recover)

	//用户
	sys := engine.Group("/user")
	{
		sys.GET("/getpublicKey", user.User.GetPublicKey)
		sys.POST("/login", user.User.Login)
	}

	//通知
	notice := engine.Group("/notice")
	{
		notice.GET("/demo", user.User.GetUser)
	}

	//文件
	file := engine.Group("/file")
	{
		file.GET("/Auth", user.User.Login)
	}
}
