mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 10:13:01 +00:00
feat:Routes are added directly to the structure
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
tools2 "go-admin/tools"
|
tools2 "go-admin/tools"
|
||||||
"go-admin/tools/app"
|
"go-admin/tools/app"
|
||||||
"go-admin/tools/config"
|
"go-admin/tools/config"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
@@ -90,6 +91,26 @@ func GenCode(c *gin.Context) {
|
|||||||
tools2.FileCreate(b3, "./router/"+tab.PackageName+".go")
|
tools2.FileCreate(b3, "./router/"+tab.PackageName+".go")
|
||||||
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js")
|
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js")
|
||||||
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue")
|
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue")
|
||||||
|
|
||||||
|
oldTest:="// {{认证路由自动补充在此处请勿删除}}"
|
||||||
|
newText:="// {{认证路由自动补充在此处请勿删除}} \r\n register"+tab.ClassName+"Router(v1,authMiddleware)"
|
||||||
|
|
||||||
|
helper := tools2.ReplaceHelper{
|
||||||
|
Root: "./router/router.go",
|
||||||
|
OldText:oldTest,
|
||||||
|
NewText: newText,
|
||||||
|
}
|
||||||
|
if helper.OldText == helper.NewText{
|
||||||
|
log.Println("error !! the NewText isEqual the OldText")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := helper.DoWrok(); err != nil {
|
||||||
|
log.Print("error:", err.Error())
|
||||||
|
|
||||||
|
} else {
|
||||||
|
log.Print("done!")
|
||||||
|
}
|
||||||
|
|
||||||
app.OK(c, "", "代码生成成功!")
|
app.OK(c, "", "代码生成成功!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-10
@@ -23,22 +23,19 @@ func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gi
|
|||||||
// 无需认证的路由示例
|
// 无需认证的路由示例
|
||||||
func examplesNoCheckRoleRouter(r *gin.Engine) {
|
func examplesNoCheckRoleRouter(r *gin.Engine) {
|
||||||
|
|
||||||
//v1 := r.Group("/api/v1")
|
v1 := r.Group("/api/v1")
|
||||||
//v1.GET("/examples/list", examples.apis)
|
v1.GET("/nilcheckrole", nil)
|
||||||
|
|
||||||
|
// {{无需认证路由自动补充在此处请勿删除}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 需要认证的路由示例
|
// 需要认证的路由示例
|
||||||
func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) {
|
func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) {
|
||||||
//v1 := r.Group("/api/v1")
|
v1 := r.Group("/api/v1")
|
||||||
//v1auth := v1.Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
v1.GET("/checkrole",nil)
|
||||||
//{
|
|
||||||
// registerDemoRouter(v1auth)
|
// {{认证路由自动补充在此处请勿删除}}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//func registerDemoRouter(v1 gin.IRoutes) {
|
|
||||||
// v1.GET("/demo", Demo)
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -112,3 +113,47 @@ func FileZip(dst, src string,notContPath string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ReplaceHelper struct {
|
||||||
|
Root string //路径
|
||||||
|
OldText string //需要替换的文本
|
||||||
|
NewText string //新的文本
|
||||||
|
}
|
||||||
|
func (h *ReplaceHelper) DoWrok() error {
|
||||||
|
|
||||||
|
return filepath.Walk(h.Root, h.walkCallback)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error {
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if f == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if f.IsDir() {
|
||||||
|
log.Println("DIR:",path)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//文件类型需要进行过滤
|
||||||
|
|
||||||
|
buf, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
//err
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
content := string(buf)
|
||||||
|
log.Printf("h.OldText: %s \n",h.OldText)
|
||||||
|
log.Printf("h.NewText: %s \n",h.NewText)
|
||||||
|
|
||||||
|
//替换
|
||||||
|
newContent := strings.Replace(content, h.OldText, h.NewText, -1)
|
||||||
|
|
||||||
|
//重新写入
|
||||||
|
ioutil.WriteFile(path, []byte(newContent), 0)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user