feature:后端路由注册和数据库注册方法与原始框架分离,自定业务不再干扰原始框架内容。

This commit is contained in:
pixelmaxQM
2024-06-23 17:00:37 +08:00
parent b628bd7769
commit 6e2140258e
7 changed files with 55 additions and 13 deletions

View File

@@ -58,5 +58,12 @@ func RegisterTables() {
global.GVA_LOG.Error("register table failed", zap.Error(err))
os.Exit(0)
}
err = bizModel(db)
if err != nil {
global.GVA_LOG.Error("register biz_table failed", zap.Error(err))
os.Exit(0)
}
global.GVA_LOG.Info("register table success")
}

View File

@@ -0,0 +1,9 @@
package initialize
import (
"gorm.io/gorm"
)
func bizModel(db *gorm.DB) error {
return db.AutoMigrate()
}

View File

@@ -61,6 +61,11 @@ func Routers() *gin.Engine {
// 方便统一添加路由组前缀 多服务器上线使用
PublicGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
PrivateGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
{
// 健康监测
PublicGroup.GET("/health", func(c *gin.Context) {
@@ -71,8 +76,7 @@ func Routers() *gin.Engine {
systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
systemRouter.InitInitRouter(PublicGroup) // 自动初始化相关
}
PrivateGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
{
systemRouter.InitApiRouter(PrivateGroup, PublicGroup) // 注册功能api路由
systemRouter.InitJwtRouter(PrivateGroup) // jwt相关路由
@@ -96,6 +100,9 @@ func Routers() *gin.Engine {
//插件路由安装
InstallPlugin(PrivateGroup, PublicGroup)
// 注册业务路由
initBizRouter(PrivateGroup, PublicGroup)
global.GVA_LOG.Info("router register success")
return Router
}

View File

@@ -0,0 +1,19 @@
package initialize
import (
"github.com/flipped-aurora/gin-vue-admin/server/router"
"github.com/gin-gonic/gin"
)
// 占位方法保证文件可以正确加载避免go空变量检测报错请勿删除。
func holder(routers ...*gin.RouterGroup) {
_ = routers
_ = router.RouterGroupApp
}
func initBizRouter(routers ...*gin.RouterGroup) {
publicGroup := routers[0]
privateGroup := routers[1]
holder(publicGroup, privateGroup)
}