3 Star 1 Fork 902

高煜涛/gin-vue-admin

forked from pixel/gin-vue-admin 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
router.go 6.66 KB
一键复制 编辑 原始数据 按行查看 历史
高煜涛 提交于 2024-09-05 21:28 . 24/9/5
package initialize
import (
swaggerFiles "github.com/swaggo/files"
"net/http"
"gitee.com/g-qs/gin-vue-admin/server/docs"
"gitee.com/g-qs/gin-vue-admin/server/global"
"gitee.com/g-qs/gin-vue-admin/server/middleware"
"gitee.com/g-qs/gin-vue-admin/server/router"
"github.com/gin-gonic/gin"
ginSwagger "github.com/swaggo/gin-swagger"
"os"
)
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
}
// 初始化总路由
func Routers() *gin.Engine {
Router := gin.New()
Router.Use(gin.Recovery())
if gin.Mode() == gin.DebugMode {
Router.Use(gin.Logger())
}
InstallPlugin(Router) // 安装插件
systemRouter := router.RouterGroupApp.System
exampleRouter := router.RouterGroupApp.Example
// 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
// VUE_APP_BASE_API = /
// VUE_APP_BASE_PATH = http://localhost
// 然后执行打包命令 npm run build。在打开下面3行注释
// Router.Static("/favicon.ico", "./dist/favicon.ico")
// Router.Static("/assets", "./dist/assets") // dist里面的静态资源
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
userRouter := router.RouterGroupApp.User
indexRouter := router.RouterGroupApp.Index
HealthRouter := router.RouterGroupApp.Health
AssessRouter := router.RouterGroupApp.Assess
diseaseRouter := router.RouterGroupApp.Disease
bodyRouter := router.RouterGroupApp.Body
cancerRouter := router.RouterGroupApp.Cancer
dateRouter := router.RouterGroupApp.Catering
adminRouter := router.RouterGroupApp.Admin
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文件")
// 跨域,如需跨域可以打开下面的注释
// Router.Use(middleware.Cors()) // 直接放行全部跨域请求
// Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
//global.GVA_LOG.Info("use middleware cors")
docs.SwaggerInfo.BasePath = global.GVA_CONFIG.System.RouterPrefix
Router.GET(global.GVA_CONFIG.System.RouterPrefix+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
global.GVA_LOG.Info("register swagger handler")
// 方便统一添加路由组前缀 多服务器上线使用
PublicGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
{
// 健康监测
PublicGroup.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, "ok")
})
}
{
systemRouter.InitBaseRouter(PublicGroup)
systemRouter.InitInitRouter(PublicGroup)
}
{
userRouter.InitBaseRouter(PublicGroup)
}
PrivateGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
{
systemRouter.InitApiRouter(PrivateGroup, PublicGroup)
systemRouter.InitJwtRouter(PrivateGroup)
systemRouter.InitUserRouter(PrivateGroup)
systemRouter.InitMenuRouter(PrivateGroup)
systemRouter.InitSystemRouter(PrivateGroup)
systemRouter.InitCasbinRouter(PrivateGroup)
systemRouter.InitAutoCodeRouter(PrivateGroup)
systemRouter.InitAuthorityRouter(PrivateGroup)
systemRouter.InitSysDictionaryRouter(PrivateGroup)
systemRouter.InitAutoCodeHistoryRouter(PrivateGroup)
systemRouter.InitSysOperationRecordRouter(PrivateGroup)
systemRouter.InitSysDictionaryDetailRouter(PrivateGroup)
systemRouter.InitAuthorityBtnRouterRouter(PrivateGroup)
systemRouter.InitSysExportTemplateRouter(PrivateGroup) // 导出模板
exampleRouter.InitCustomerRouter(PrivateGroup)
exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup)
}
{
userRouter.InitUserRouter(PrivateGroup, PublicGroup)
userRouter.InitUserBindManageRouter(PrivateGroup)
indexRouter.InitIndexRouter(PrivateGroup)
HealthRouter.InitCircleRouter(PrivateGroup)
AssessRouter.InitAssessRouter(PrivateGroup)
diseaseRouter.InitDiseaseRouter(PrivateGroup)
bodyRouter.InitBodyRouter(PrivateGroup)
cancerRouter.InitCancerRouter(PrivateGroup)
}
{
structureRouter := router.RouterGroupApp.Structure
structureRouter.InitServiceStationArticleRouter(PrivateGroup, PublicGroup)
}
{
configRouter := router.RouterGroupApp.Config
configRouter.InitConfigRouter(PrivateGroup)
}
{
topicRouter := router.RouterGroupApp.Topic
topicRouter.InitTopicRouter(PrivateGroup)
}
{
hierarchyRouter := router.RouterGroupApp.Hierarchy
hierarchyRouter.InitLevelOneRouter(PrivateGroup)
hierarchyRouter.InitLevelTwoRouter(PrivateGroup, PublicGroup)
hierarchyRouter.InitLevelThreeRouter(PrivateGroup)
hierarchyRouter.InitFdArticleGraphicRouter(PrivateGroup, PublicGroup)
hierarchyRouter.InitFdArticleAudioRouter(PrivateGroup, PublicGroup)
hierarchyRouter.InitFdArticleVideoRouter(PrivateGroup, PublicGroup)
hierarchyRouter.InitFdArticleLearnRouter(PrivateGroup, PublicGroup)
hierarchyRouter.InitFdArticleRouter(PrivateGroup, PublicGroup)
hierarchyRouter.InitCommentRouter(PrivateGroup, PublicGroup)
}
{
feedbackRouter := router.RouterGroupApp.Feedback
feedbackRouter.InitFeedbackRouter(PrivateGroup, PublicGroup)
}
{
healthRouter := router.RouterGroupApp.Health
healthRouter.InitPhysiqueRouter(PrivateGroup, PublicGroup)
healthRouter.InitDiseaseRouter(PrivateGroup, PublicGroup)
healthRouter.InitShipuRouter(PrivateGroup, PublicGroup)
healthRouter.InitFdEfficacyRouter(PrivateGroup)
healthRouter.InitFdJqRouter(PrivateGroup)
healthRouter.InitHealthQAndARouter(PrivateGroup)
healthRouter.InitHealthQuestionRouter(PrivateGroup)
}
{
dateRouter.InitDateRouter(PrivateGroup, PublicGroup)
}
{
cateringRouter := router.RouterGroupApp.Catering
cateringRouter.InitFoodRouter(PrivateGroup)
}
{
publicRouter := router.RouterGroupApp.Public
publicRouter.InitOnlineServiceRouter(PrivateGroup)
publicRouter.InitMessageRouter(PrivateGroup, PublicGroup)
}
{
adminRouter.InitAdminUserRouter(PrivateGroup)
adminRouter.InitDataAnalysisRouter(PrivateGroup)
}
{
managerRouter := router.RouterGroupApp.Manager
managerRouter.InitFdHealthManagerRouter(PrivateGroup, PublicGroup)
managerRouter.InitFdHealthManagerRegisterRouter(PrivateGroup)
managerRouter.InitFdHealthManagerAuditRouter(PrivateGroup)
managerRouter.InitMessageRemindRouter(PrivateGroup)
managerRouter.InitTargetPlanRouter(PrivateGroup)
}
{
dashboardRouter := router.RouterGroupApp.Dashboard
dashboardRouter.InitBordRouter(PrivateGroup)
}
global.GVA_LOG.Info("router register success")
return Router
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/g-qs/gin-vue-admin.git
git@gitee.com:g-qs/gin-vue-admin.git
g-qs
gin-vue-admin
gin-vue-admin
533102b8437a

搜索帮助