feat:gen code to path
This commit is contained in:
1 parent
cd60410ac0
commit
75eec8eebe
4 files changed
+25
-19
No files matched your search
+4
-6
@@ -49,7 +49,6 @@ func Preview(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
|
||||
func GenCode(c *gin.Context) {
|
||||
table := tools.SysTables{}
|
||||
id, err := tools2.StringToInt(c.Param("tableId"))
|
||||
@@ -63,10 +62,9 @@ func GenCode(c *gin.Context) {
|
||||
t3, err := template.ParseFiles("template/router.go.template")
|
||||
tools2.HasError(err, "", -1)
|
||||
tab, _ := table.Get()
|
||||
_ = tools2.PathCreate("./apis/")
|
||||
_ = tools2.PathCreate("./apis/")
|
||||
_ = tools2.PathCreate("./apis/" + tab.ModuleName + "/")
|
||||
_ = tools2.PathCreate("./models/")
|
||||
_ = tools2.PathCreate("./router/" + tab.ModuleName + "/")
|
||||
_ = tools2.PathCreate("./router/")
|
||||
|
||||
var b1 bytes.Buffer
|
||||
err = t1.Execute(&b1, tab)
|
||||
@@ -75,7 +73,7 @@ func GenCode(c *gin.Context) {
|
||||
var b3 bytes.Buffer
|
||||
err = t3.Execute(&b3, tab)
|
||||
tools2.FileCreate(b1, "./models/"+tab.PackageName+".go")
|
||||
tools2.FileCreate(b2, "./apis/"+tab.PackageName+".go")
|
||||
tools2.FileCreate(b2, "./apis/"+tab.ModuleName+"/"+tab.PackageName+".go")
|
||||
tools2.FileCreate(b3, "./router/"+tab.PackageName+".go")
|
||||
|
||||
app.OK(c, "", "代码生成成功!")
|
||||
}
|
||||
@@ -52,6 +52,8 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) {
|
||||
v1.GET("/monitor/server", monitor.ServerInfo)
|
||||
v1.GET("/getCaptcha", system.GenerateCaptchaHandler)
|
||||
v1.GET("/gen/preview/:tableId", Preview)
|
||||
v1.GET("/gen/toproject/:tableId", GenCode)
|
||||
|
||||
v1.GET("/menuTreeselect", system.GetMenuTreeelect)
|
||||
v1.GET("/dict/databytype/:dictType", dict.GetDictDataByDictType)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package apis
|
||||
package {{.ModuleName}}
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
+18
-12
@@ -1,3 +1,11 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/middleware"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
"go-admin/apis/{{.ModuleName}}"
|
||||
)
|
||||
|
||||
// 需认证的路由代码
|
||||
func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
@@ -18,16 +26,14 @@ l.GET("/{{.ModuleName}}List",{{.ModuleName}}.Get{{.ClassName}}List)
|
||||
}
|
||||
|
||||
// 无需认证的路由代码
|
||||
func register{{.ClassName}}Router(v1 *gin.RouterGroup) {
|
||||
|
||||
v1.GET("/{{.ModuleName}}List",{{.ModuleName}}.Get{{.ClassName}}List)
|
||||
|
||||
r := v1.Group("/{{.ModuleName}}")
|
||||
{
|
||||
r.GET("/:{{.PkJsonField}}", {{.ModuleName}}.Get{{.ClassName}})
|
||||
r.POST("", {{.ModuleName}}.Insert{{.ClassName}})
|
||||
r.PUT("", {{.ModuleName}}.Update{{.ClassName}})
|
||||
r.DELETE("/:{{.PkJsonField}}", {{.ModuleName}}.Delete{{.ClassName}})
|
||||
}
|
||||
}
|
||||
// func register{{.ClassName}}Router(v1 *gin.RouterGroup) {
|
||||
// v1.GET("/{{.ModuleName}}List",{{.ModuleName}}.Get{{.ClassName}}List)
|
||||
// r := v1.Group("/{{.ModuleName}}")
|
||||
// {
|
||||
// r.GET("/:{{.PkJsonField}}", {{.ModuleName}}.Get{{.ClassName}})
|
||||
// r.POST("", {{.ModuleName}}.Insert{{.ClassName}})
|
||||
// r.PUT("", {{.ModuleName}}.Update{{.ClassName}})
|
||||
// r.DELETE("/:{{.PkJsonField}}", {{.ModuleName}}.Delete{{.ClassName}})
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in new issue
Block a user