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

@@ -22,7 +22,7 @@ func RollGormBack(pk, model string) {
// 首先分析存在多少个ttt作为调用方的node块
// 如果多个 仅仅删除对应块即可
// 如果单个 那么还需要剔除import
path := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "initialize", "gorm.go")
path := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "initialize", "gorm_biz.go")
src, err := os.ReadFile(path)
if err != nil {
fmt.Println(err)
@@ -60,7 +60,7 @@ func RollGormBack(pk, model string) {
}
return true
})
if k > 0 {
if k > -1 {
n.Args = append(append([]ast.Expr{}, n.Args[:k]...), n.Args[k+1:]...)
}
if pkNum == 1 {
@@ -99,7 +99,7 @@ func RollRouterBack(pk, model string) {
// 首先抓到所有的代码块结构 {}
// 分析结构中是否存在一个变量叫做 pk+Router
// 然后获取到代码块指针 对内部需要回滚的代码进行剔除
path := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "initialize", "router.go")
path := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "initialize", "router_biz.go")
src, err := os.ReadFile(path)
if err != nil {
fmt.Println(err)
@@ -115,7 +115,7 @@ func RollRouterBack(pk, model string) {
ast.Inspect(astFile, func(node ast.Node) bool {
if n, ok := node.(*ast.FuncDecl); ok {
if n.Name.Name == "Routers" {
if n.Name.Name == "initBizRouter" {
routerStmt = n
}
}

View File

@@ -61,7 +61,7 @@ func AddRouterCode(path, funcName, pk, model string) {
},
}
FuncNode.Body.List = AppendNodeToList(FuncNode.Body.List, routerNode, len(FuncNode.Body.List)-2)
FuncNode.Body.List = AppendNodeToList(FuncNode.Body.List, routerNode, len(FuncNode.Body.List)-1)
bloctPre = routerNode
} else {
bloctPre = b
@@ -77,10 +77,10 @@ func AddRouterCode(path, funcName, pk, model string) {
},
Args: []ast.Expr{
&ast.Ident{
Name: "PrivateGroup",
Name: "privateGroup",
},
&ast.Ident{
Name: "PublicGroup",
Name: "publicGroup",
},
},
},