You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
4 months ago
|
package initialize
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
_ "service-api/docs"
|
||
|
"service-api/global"
|
||
|
"service-api/middleware"
|
||
|
"service-api/router"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
// 初始化总路由
|
||
|
|
||
|
func Routers() *gin.Engine {
|
||
|
var Router = gin.Default()
|
||
|
Router.StaticFS(global.MG_CONFIG.Local.Path, http.Dir(global.MG_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址
|
||
|
// Router.Use(middleware.LoadTls()) // 打开就能玩https了
|
||
|
global.MG_LOG.Info("use middleware logger")
|
||
|
// 跨域
|
||
|
Router.Use(middleware.Cors()) // 如需跨域可以打开
|
||
|
global.MG_LOG.Info("use middleware cors")
|
||
|
// Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||
|
//global.MG_LOG.Info("register swagger handler")
|
||
|
// Router.Any("/ueditor/controller", service.UeditorAction) //百度富文本编辑器
|
||
|
// 方便统一添加路由组前缀 多服务器上线使用
|
||
|
PublicGroup := Router.Group("")
|
||
|
{
|
||
|
router.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
|
||
|
}
|
||
|
PrivateGroup := Router.Group("")
|
||
|
PrivateGroup.Use(middleware.JWTAuth())
|
||
|
{
|
||
|
// Code generated by service-api Begin; DO NOT EDIT.
|
||
|
// Code generated by service-api End; DO NOT EDIT.
|
||
|
}
|
||
|
global.MG_LOG.Info("router register success")
|
||
|
return Router
|
||
|
}
|