2020-04-05 08:18:19 +00:00
|
|
|
|
package initialize
|
2019-12-12 05:21:16 +00:00
|
|
|
|
|
|
|
|
|
|
import (
|
2024-05-17 08:22:16 +00:00
|
|
|
|
"net/http"
|
|
|
|
|
|
"os"
|
|
|
|
|
|
|
2023-01-14 02:22:46 +00:00
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/docs"
|
2021-08-23 15:13:24 +00:00
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
|
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/router"
|
2019-12-12 05:21:16 +00:00
|
|
|
|
"github.com/gin-gonic/gin"
|
2024-01-30 15:32:39 +00:00
|
|
|
|
swaggerFiles "github.com/swaggo/files"
|
2023-01-14 02:22:46 +00:00
|
|
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
2019-12-12 05:21:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2024-01-30 15:32:39 +00:00
|
|
|
|
type justFilesFilesystem struct {
|
|
|
|
|
|
fs http.FileSystem
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (fs justFilesFilesystem) Open(name string) (http.File, error) {
|
|
|
|
|
|
f, err := fs.fs.Open(name)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stat, err := f.Stat()
|
|
|
|
|
|
if stat.IsDir() {
|
|
|
|
|
|
return nil, os.ErrPermission
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return f, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-19 15:37:55 +00:00
|
|
|
|
// 初始化总路由
|
2020-04-20 08:21:50 +00:00
|
|
|
|
|
2020-04-05 01:18:25 +00:00
|
|
|
|
func Routers() *gin.Engine {
|
2026-01-30 06:33:57 +00:00
|
|
|
|
Router := gin.New()
|
|
|
|
|
|
// 使用自定义的 Recovery 中间件,记录 panic 并入库
|
|
|
|
|
|
Router.Use(middleware.GinRecovery(true))
|
|
|
|
|
|
if gin.Mode() == gin.DebugMode {
|
|
|
|
|
|
Router.Use(gin.Logger())
|
|
|
|
|
|
}
|
2023-11-04 13:47:49 +00:00
|
|
|
|
|
2025-10-19 05:27:48 +00:00
|
|
|
|
if !global.GVA_CONFIG.MCP.Separate {
|
2025-05-13 11:24:54 +00:00
|
|
|
|
|
2025-10-19 05:27:48 +00:00
|
|
|
|
sseServer := McpRun()
|
2025-05-13 11:24:54 +00:00
|
|
|
|
|
2025-10-19 05:27:48 +00:00
|
|
|
|
// 注册mcp服务
|
|
|
|
|
|
Router.GET(global.GVA_CONFIG.MCP.SSEPath, func(c *gin.Context) {
|
|
|
|
|
|
sseServer.SSEHandler().ServeHTTP(c.Writer, c.Request)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
Router.POST(global.GVA_CONFIG.MCP.MessagePath, func(c *gin.Context) {
|
|
|
|
|
|
sseServer.MessageHandler().ServeHTTP(c.Writer, c.Request)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-05-13 11:24:54 +00:00
|
|
|
|
|
2022-03-26 06:13:26 +00:00
|
|
|
|
systemRouter := router.RouterGroupApp.System
|
|
|
|
|
|
exampleRouter := router.RouterGroupApp.Example
|
2021-09-02 09:54:36 +00:00
|
|
|
|
// 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
|
2021-09-02 06:38:48 +00:00
|
|
|
|
// VUE_APP_BASE_API = /
|
|
|
|
|
|
// VUE_APP_BASE_PATH = http://localhost
|
2023-08-19 03:29:44 +00:00
|
|
|
|
// 然后执行打包命令 npm run build。在打开下面3行注释
|
2025-04-18 03:40:03 +00:00
|
|
|
|
// Router.StaticFile("/favicon.ico", "./dist/favicon.ico")
|
2024-07-21 03:33:25 +00:00
|
|
|
|
// Router.Static("/assets", "./dist/assets") // dist里面的静态资源
|
|
|
|
|
|
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
|
2021-09-02 06:38:48 +00:00
|
|
|
|
|
2024-01-30 15:32:39 +00:00
|
|
|
|
Router.StaticFS(global.GVA_CONFIG.Local.StorePath, justFilesFilesystem{http.Dir(global.GVA_CONFIG.Local.StorePath)}) // Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件")
|
2021-12-10 14:56:18 +00:00
|
|
|
|
// 跨域,如需跨域可以打开下面的注释
|
|
|
|
|
|
// Router.Use(middleware.Cors()) // 直接放行全部跨域请求
|
2022-11-30 08:52:00 +00:00
|
|
|
|
// Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
|
2024-07-21 03:33:25 +00:00
|
|
|
|
// global.GVA_LOG.Info("use middleware cors")
|
2023-01-14 02:22:46 +00:00
|
|
|
|
docs.SwaggerInfo.BasePath = global.GVA_CONFIG.System.RouterPrefix
|
|
|
|
|
|
Router.GET(global.GVA_CONFIG.System.RouterPrefix+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
2020-09-16 02:31:56 +00:00
|
|
|
|
global.GVA_LOG.Info("register swagger handler")
|
2020-03-24 05:34:03 +00:00
|
|
|
|
// 方便统一添加路由组前缀 多服务器上线使用
|
2021-07-17 06:18:52 +00:00
|
|
|
|
|
2023-01-14 02:22:46 +00:00
|
|
|
|
PublicGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
|
2024-06-23 09:00:37 +00:00
|
|
|
|
PrivateGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
|
|
|
|
|
|
|
|
|
|
|
|
PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
|
|
|
|
|
|
2021-09-24 06:15:16 +00:00
|
|
|
|
{
|
|
|
|
|
|
// 健康监测
|
|
|
|
|
|
PublicGroup.GET("/health", func(c *gin.Context) {
|
2022-12-08 10:14:10 +00:00
|
|
|
|
c.JSON(http.StatusOK, "ok")
|
2021-09-24 06:15:16 +00:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2020-11-20 15:26:17 +00:00
|
|
|
|
{
|
2021-07-17 06:18:52 +00:00
|
|
|
|
systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
|
|
|
|
|
|
systemRouter.InitInitRouter(PublicGroup) // 自动初始化相关
|
2020-11-20 15:26:17 +00:00
|
|
|
|
}
|
2024-06-23 09:00:37 +00:00
|
|
|
|
|
2020-11-20 15:26:17 +00:00
|
|
|
|
{
|
2025-03-15 05:31:33 +00:00
|
|
|
|
systemRouter.InitApiRouter(PrivateGroup, PublicGroup) // 注册功能api路由
|
|
|
|
|
|
systemRouter.InitJwtRouter(PrivateGroup) // jwt相关路由
|
|
|
|
|
|
systemRouter.InitUserRouter(PrivateGroup) // 注册用户路由
|
|
|
|
|
|
systemRouter.InitMenuRouter(PrivateGroup) // 注册menu路由
|
|
|
|
|
|
systemRouter.InitSystemRouter(PrivateGroup) // system相关路由
|
2025-07-31 13:21:04 +00:00
|
|
|
|
systemRouter.InitSysVersionRouter(PrivateGroup) // 发版相关路由
|
2025-03-15 05:31:33 +00:00
|
|
|
|
systemRouter.InitCasbinRouter(PrivateGroup) // 权限相关路由
|
|
|
|
|
|
systemRouter.InitAutoCodeRouter(PrivateGroup, PublicGroup) // 创建自动化代码
|
|
|
|
|
|
systemRouter.InitAuthorityRouter(PrivateGroup) // 注册角色路由
|
|
|
|
|
|
systemRouter.InitSysDictionaryRouter(PrivateGroup) // 字典管理
|
|
|
|
|
|
systemRouter.InitAutoCodeHistoryRouter(PrivateGroup) // 自动化代码历史
|
|
|
|
|
|
systemRouter.InitSysOperationRecordRouter(PrivateGroup) // 操作记录
|
|
|
|
|
|
systemRouter.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理
|
|
|
|
|
|
systemRouter.InitAuthorityBtnRouterRouter(PrivateGroup) // 按钮权限管理
|
|
|
|
|
|
systemRouter.InitSysExportTemplateRouter(PrivateGroup, PublicGroup) // 导出模板
|
|
|
|
|
|
systemRouter.InitSysParamsRouter(PrivateGroup, PublicGroup) // 参数管理
|
2025-10-28 08:19:25 +00:00
|
|
|
|
systemRouter.InitSysErrorRouter(PrivateGroup, PublicGroup) // 错误日志
|
2026-01-30 06:33:57 +00:00
|
|
|
|
systemRouter.InitLoginLogRouter(PrivateGroup) // 登录日志
|
|
|
|
|
|
systemRouter.InitApiTokenRouter(PrivateGroup) // apiToken签发
|
|
|
|
|
|
systemRouter.InitSkillsRouter(PrivateGroup) // Skills 定义器
|
2025-03-15 05:31:33 +00:00
|
|
|
|
exampleRouter.InitCustomerRouter(PrivateGroup) // 客户路由
|
|
|
|
|
|
exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
|
|
|
|
|
|
exampleRouter.InitAttachmentCategoryRouterRouter(PrivateGroup) // 文件上传下载分类
|
2021-03-19 15:24:55 +00:00
|
|
|
|
|
2020-11-20 15:26:17 +00:00
|
|
|
|
}
|
2021-08-22 04:21:32 +00:00
|
|
|
|
|
2024-05-17 08:22:16 +00:00
|
|
|
|
//插件路由安装
|
2024-06-28 16:22:53 +00:00
|
|
|
|
InstallPlugin(PrivateGroup, PublicGroup, Router)
|
2024-05-17 08:22:16 +00:00
|
|
|
|
|
2024-06-23 09:00:37 +00:00
|
|
|
|
// 注册业务路由
|
|
|
|
|
|
initBizRouter(PrivateGroup, PublicGroup)
|
|
|
|
|
|
|
2024-07-04 13:19:20 +00:00
|
|
|
|
global.GVA_ROUTERS = Router.Routes()
|
|
|
|
|
|
|
2020-04-05 08:18:19 +00:00
|
|
|
|
global.GVA_LOG.Info("router register success")
|
2019-12-12 05:21:16 +00:00
|
|
|
|
return Router
|
|
|
|
|
|
}
|