feat : update actions gen

This commit is contained in:
zhangwenjian committed 2020-09-10 02:14:48 +08:00
1 parent aaba20d42a
commit fa07a57d22
14 files changed
+158 -110

No files matched your search

+81 -29
View File
@@ -30,7 +30,7 @@ func Preview(c *gin.Context) {
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/router.go.template") t5, err := template.ParseFiles("template/router.go.template")
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/dto.go.template") t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
tab, _ := table.Get() tab, _ := table.Get()
var b1 bytes.Buffer var b1 bytes.Buffer
@@ -68,7 +68,6 @@ func GenCode(c *gin.Context) {
routerfile := "template/routercheckrole.go.template" routerfile := "template/routercheckrole.go.template"
oldTest := "// {{认证路由自动补充在此处请勿删除}}" oldTest := "// {{认证路由自动补充在此处请勿删除}}"
newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)" newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
@@ -88,7 +87,7 @@ func GenCode(c *gin.Context) {
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/vue.go.template") t5, err := template.ParseFiles("template/vue.go.template")
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/dto.go.template") t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./apis/" + tab.ModuleName + "/") _ = tools2.PathCreate("./apis/" + tab.ModuleName + "/")
@@ -136,7 +135,6 @@ func GenCode(c *gin.Context) {
app.OK(c, "", "Code generated successfully!") app.OK(c, "", "Code generated successfully!")
} }
func GenCodeV2(c *gin.Context) { func GenCodeV2(c *gin.Context) {
table := tools.SysTables{} table := tools.SysTables{}
id, err := tools2.StringToInt(c.Param("tableId")) id, err := tools2.StringToInt(c.Param("tableId"))
@@ -144,14 +142,23 @@ func GenCodeV2(c *gin.Context) {
table.TableId = id table.TableId = id
tab, _ := table.Get() tab, _ := table.Get()
routerfile := "template/v1.2/routercheckrole.go.template" if tab.IsActions {
ActionsGen(tab)
} else {
if !tab.IsAuth { NOActionsGen(tab)
routerfile = "template/v1.2/routernocheckrole.go.template"
} }
t1, err := template.ParseFiles("template/v1.2/model.go.template") app.OK(c, "", "Code generated successfully!")
}
func NOActionsGen(tab tools.SysTables) {
routerfile := "template/routercheckrole.go.template"
if !tab.IsAuth {
routerfile = "template/routernocheckrole.go.template"
}
t1, err := template.ParseFiles("template/model.go.template")
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
t2, err := template.ParseFiles("template/api.go.template") t2, err := template.ParseFiles("template/api.go.template")
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
@@ -161,15 +168,15 @@ func GenCodeV2(c *gin.Context) {
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/vue.go.template") t5, err := template.ParseFiles("template/vue.go.template")
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/v1.2/dto.go.template") t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1) tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./app/admin/apis/" + tab.ModuleName + "/") _ = tools2.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName + "/")
_ = tools2.PathCreate("./app/admin/models/") _ = tools2.PathCreate("./app/" + tab.PackageName + "/models/")
_ = tools2.PathCreate("./app/admin/router/") _ = tools2.PathCreate("./app/" + tab.PackageName + "/router/")
_ = tools2.PathCreate("./app/admin/dto/") _ = tools2.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/") _ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName) _ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.BusinessName)
var b1 bytes.Buffer var b1 bytes.Buffer
err = t1.Execute(&b1, tab) err = t1.Execute(&b1, tab)
@@ -183,15 +190,60 @@ func GenCodeV2(c *gin.Context) {
err = t5.Execute(&b5, tab) err = t5.Execute(&b5, tab)
var b6 bytes.Buffer var b6 bytes.Buffer
err = t6.Execute(&b6, tab) err = t6.Execute(&b6, tab)
tools2.FileCreate(b1, "./app/admin/models/"+tab.PackageName+".go") tools2.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.BusinessName+".go")
tools2.FileCreate(b2, "./app/admin/apis/"+tab.ModuleName+"/"+tab.PackageName+".go") tools2.FileCreate(b2, "./app/"+tab.PackageName+"/apis/"+tab.ModuleName+"/"+tab.BusinessName+".go")
tools2.FileCreate(b3, "./app/admin/router/"+tab.PackageName+".go") tools2.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js") tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.BusinessName+".js")
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue") tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.BusinessName+"/index.vue")
tools2.FileCreate(b6, "./app/admin/service/dto/"+tab.PackageName+".go") tools2.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
}
app.OK(c, "", "Code generated successfully!") func ActionsGen(tab tools.SysTables) {
routerfile := "template/v2/routercheckrole.go.template"
if !tab.IsAuth {
routerfile = "template/v2/routernocheckrole.go.template"
}
t1, err := template.ParseFiles("template/v2/model.go.template")
tools2.HasError(err, "", -1)
//t2, err := template.ParseFiles("template/v2/router.go.template")
//tools2.HasError(err, "", -1)
t3, err := template.ParseFiles(routerfile)
tools2.HasError(err, "", -1)
t4, err := template.ParseFiles("template/js.go.template")
tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/vue.go.template")
tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/models/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/router/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.BusinessName)
var b1 bytes.Buffer
err = t1.Execute(&b1, tab)
//var b2 bytes.Buffer
//err = t2.Execute(&b2, tab)
var b3 bytes.Buffer
err = t3.Execute(&b3, tab)
var b4 bytes.Buffer
err = t4.Execute(&b4, tab)
var b5 bytes.Buffer
err = t5.Execute(&b5, tab)
var b6 bytes.Buffer
err = t6.Execute(&b6, tab)
tools2.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.BusinessName+".go")
//tools2.FileCreate(b2, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
tools2.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.BusinessName+".js")
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.BusinessName+"/index.vue")
tools2.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
} }
func GenMenuAndApi(c *gin.Context) { func GenMenuAndApi(c *gin.Context) {
@@ -228,10 +280,10 @@ func GenMenuAndApi(c *gin.Context) {
Cmenu.Path = tab.TBName Cmenu.Path = tab.TBName
Cmenu.MenuType = "C" Cmenu.MenuType = "C"
Cmenu.Action = "无" Cmenu.Action = "无"
Cmenu.Permission = tab.PackageName + ":" + tab.ModuleName + ":list" Cmenu.Permission = tab.ModuleName + ":" + tab.BusinessName + ":list"
Cmenu.ParentId = Mmenu.MenuId Cmenu.ParentId = Mmenu.MenuId
Cmenu.NoCache = false Cmenu.NoCache = false
Cmenu.Component = "/" + tab.ModuleName + "/index" Cmenu.Component = "/" + tab.BusinessName + "/index"
Cmenu.Sort = 0 Cmenu.Sort = 0
Cmenu.Visible = "0" Cmenu.Visible = "0"
Cmenu.IsFrame = "0" Cmenu.IsFrame = "0"
@@ -248,7 +300,7 @@ func GenMenuAndApi(c *gin.Context) {
MList.Path = tab.TBName MList.Path = tab.TBName
MList.MenuType = "F" MList.MenuType = "F"
MList.Action = "无" MList.Action = "无"
MList.Permission = tab.PackageName + ":" + tab.ModuleName + ":query" MList.Permission = tab.ModuleName + ":" + tab.BusinessName + ":query"
MList.ParentId = Cmenu.MenuId MList.ParentId = Cmenu.MenuId
MList.NoCache = false MList.NoCache = false
MList.Sort = 0 MList.Sort = 0
@@ -267,7 +319,7 @@ func GenMenuAndApi(c *gin.Context) {
MCreate.Path = tab.TBName MCreate.Path = tab.TBName
MCreate.MenuType = "F" MCreate.MenuType = "F"
MCreate.Action = "无" MCreate.Action = "无"
MCreate.Permission = tab.PackageName + ":" + tab.ModuleName + ":add" MCreate.Permission = tab.ModuleName + ":" + tab.BusinessName + ":add"
MCreate.ParentId = Cmenu.MenuId MCreate.ParentId = Cmenu.MenuId
MCreate.NoCache = false MCreate.NoCache = false
MCreate.Sort = 0 MCreate.Sort = 0
@@ -286,7 +338,7 @@ func GenMenuAndApi(c *gin.Context) {
MUpdate.Path = tab.TBName MUpdate.Path = tab.TBName
MUpdate.MenuType = "F" MUpdate.MenuType = "F"
MUpdate.Action = "无" MUpdate.Action = "无"
MUpdate.Permission = tab.PackageName + ":" + tab.ModuleName + ":edit" MUpdate.Permission = tab.ModuleName + ":" + tab.BusinessName + ":edit"
MUpdate.ParentId = Cmenu.MenuId MUpdate.ParentId = Cmenu.MenuId
MUpdate.NoCache = false MUpdate.NoCache = false
MUpdate.Sort = 0 MUpdate.Sort = 0
@@ -305,7 +357,7 @@ func GenMenuAndApi(c *gin.Context) {
MDelete.Path = tab.TBName MDelete.Path = tab.TBName
MDelete.MenuType = "F" MDelete.MenuType = "F"
MDelete.Action = "无" MDelete.Action = "无"
MDelete.Permission = tab.PackageName + ":" + tab.ModuleName + ":remove" MDelete.Permission = tab.ModuleName + ":" + tab.BusinessName + ":remove"
MDelete.ParentId = Cmenu.MenuId MDelete.ParentId = Cmenu.MenuId
MDelete.NoCache = false MDelete.NoCache = false
MDelete.Sort = 0 MDelete.Sort = 0
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"go-admin/app/admin/middleware" "go-admin/app/admin/middleware"
"go-admin/app/admin/middleware/handler" "go-admin/app/admin/middleware/handler"
"go-admin/common/global" "go-admin/common/global"
jwt "go-admin/pkg/jwtauth"
_ "go-admin/pkg/jwtauth" _ "go-admin/pkg/jwtauth"
"go-admin/tools" "go-admin/tools"
config2 "go-admin/tools/config" config2 "go-admin/tools/config"
@@ -19,7 +18,7 @@ func InitRouter(r *gin.Engine) *gin.Engine {
middleware.InitMiddleware(r) middleware.InitMiddleware(r)
// the jwt middleware // the jwt middleware
var err error var err error
authMiddleware, err = middleware.AuthInit() authMiddleware, err := middleware.AuthInit()
tools.HasError(err, "JWT Init Error", 500) tools.HasError(err, "JWT Init Error", 500)
// 注册系统路由 // 注册系统路由
+1 -1
View File
@@ -65,7 +65,7 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) {
v1.GET("/monitor/server", monitor.ServerInfo) v1.GET("/monitor/server", monitor.ServerInfo)
v1.GET("/getCaptcha", system.GenerateCaptchaHandler) v1.GET("/getCaptcha", system.GenerateCaptchaHandler)
v1.GET("/gen/preview/:tableId", Preview) v1.GET("/gen/preview/:tableId", Preview)
v1.GET("/gen/toproject/:tableId", GenCode) v1.GET("/gen/toproject/:tableId", GenCodeV2)
v1.GET("/gen/todb/:tableId", GenMenuAndApi) v1.GET("/gen/todb/:tableId", GenMenuAndApi)
v1.GET("/gen/tabletree", GetSysTablesTree) v1.GET("/gen/tabletree", GetSysTablesTree)
v1.GET("/menuTreeselect", system.GetMenuTreeelect) v1.GET("/menuTreeselect", system.GetMenuTreeelect)
+1
View File
@@ -2,6 +2,7 @@ package dto
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go-admin/app/admin/models" "go-admin/app/admin/models"
"go-admin/common/dto" "go-admin/common/dto"
models2 "go-admin/common/models" models2 "go-admin/common/models"
+1 -2
View File
@@ -7,7 +7,6 @@ import (
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/gorm" "gorm.io/gorm"
"go-admin/app/admin/router"
"go-admin/common/global" "go-admin/common/global"
mycasbin "go-admin/pkg/casbin" mycasbin "go-admin/pkg/casbin"
"go-admin/pkg/logger" "go-admin/pkg/logger"
@@ -22,6 +21,6 @@ func main() {
mycasbin.Setup() mycasbin.Setup()
logger.Setup() logger.Setup()
global.GinEngine = gin.Default() global.GinEngine = gin.Default()
router.InitRouter() //router.InitRouter()
log.Fatal(global.GinEngine.Run(":8000")) log.Fatal(global.GinEngine.Run(":8000"))
} }
+4 -3
View File
@@ -30,17 +30,18 @@ data: data
// 修改{{.ClassName}} // 修改{{.ClassName}}
export function update{{.ClassName}}(data) { export function update{{.ClassName}}(data) {
return request({ return request({
url: '/api/v1/{{.ModuleName}}', url: '/api/v1/{{.ModuleName}}/'+data.{{.PkJsonField}},
method: 'put', method: 'put',
data: data data: data
}) })
} }
// 删除{{.ClassName}} // 删除{{.ClassName}}
export function del{{.ClassName}}({{.PkJsonField}}) { export function del{{.ClassName}}({{.PkJsonField}},data) {
return request({ return request({
url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}}, url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}},
method: 'delete' method: 'delete',
data: data
}) })
} }
+6 -1
View File
@@ -1,8 +1,13 @@
package models package models
import ( import (
orm "go-admin/global" "strconv"
"go-admin/common/dto"
orm "go-admin/common/global"
"go-admin/common/models"
"go-admin/tools" "go-admin/tools"
{{ range .Columns }} {{ range .Columns }}
{{- if eq .GoField "CreatedAt" -}} {{- if eq .GoField "CreatedAt" -}}
{{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}}
@@ -5,11 +5,10 @@ import (
"go-admin/app/admin/models" "go-admin/app/admin/models"
"go-admin/common/dto" "go-admin/common/dto"
models2 "go-admin/common/models" models2 "go-admin/common/models"
"net/http"
) )
type {{.ClassName}}Search struct { type {{.ClassName}}Search struct {
Pagination `search:"-"` dto.Pagination `search:"-"`
{{ $tablename := .TBName -}} {{ $tablename := .TBName -}}
{{ range .Columns -}} {{ range .Columns -}}
{{$z := .IsQuery}} {{$z := .IsQuery}}
@@ -75,29 +74,16 @@ func (s *{{.ClassName}}Control) GenerateM() (models2.ActiveRecord, error) {
{{- else }} {{- else }}
{{.GoField}}: s.{{.GoField}}, {{.GoField}}: s.{{.GoField}},
{{- end }} {{- end }}
{{- end }}
}, nil }, nil
} }
func (s *{{.ClassName}}Control) GetId() interface{} { func (s *{{.ClassName}}Control) GetId() interface{} {
return s.{{.PkColumn}} return s.{{.PkGoField}}
} }
type {{.ClassName}}ById struct { type {{.ClassName}}ById struct {
Id int `uri:"id" validate:"required"` dto.ObjectById
Ids []int `json:"ids"`
}
func (s *{{.ClassName}}ById) Bind(ctx *gin.Context) error {
if ctx.Request.Method == http.MethodDelete {
err := ctx.Bind(s)
if err != nil {
return err
}
if len(s.Ids) > 0 {
return nil
}
}
return ctx.BindUri(s)
} }
func (s *{{.ClassName}}ById) Generate() dto.Control { func (s *{{.ClassName}}ById) Generate() dto.Control {
@@ -108,10 +94,3 @@ func (s *{{.ClassName}}ById) Generate() dto.Control {
func (s *{{.ClassName}}ById) GenerateM() (models2.ActiveRecord, error) { func (s *{{.ClassName}}ById) GenerateM() (models2.ActiveRecord, error) {
return &models.{{.ClassName}}{}, nil return &models.{{.ClassName}}{}, nil
} }
func (s *{{.ClassName}}ById) GetId() interface{} {
if len(s.Ids) > 0 {
return s.Ids
}
return s.Id
}
@@ -1,14 +1,17 @@
package models package models
import ( import (
"go-admin/common/dto"
orm "go-admin/common/global"
"go-admin/common/models"
"go-admin/tools"
"strconv" "strconv"
{{- if eq .IsActions true -}}
{{- else }}
"go-admin/common/dto"
"go-admin/tools"
orm "go-admin/common/global"
{{ end }}
"go-admin/common/models"
) )
type SysJob struct { type {{.ClassName}} struct {
{{ range .Columns -}} {{ range .Columns -}}
{{$x := .Pk}} {{$x := .Pk}}
{{- if ($x) }} {{- if ($x) }}
@@ -34,7 +37,7 @@ func (e *{{.ClassName}}) Generate() models.ActiveRecord {
} }
func (e *{{.ClassName}}) GetId() interface{} { func (e *{{.ClassName}}) GetId() interface{} {
return e.{{.PkColumn}} return e.{{.PkGoField}}
} }
func (e *{{.ClassName}}) SetCreateBy(createBy uint) { func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
@@ -3,7 +3,6 @@ package router
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go-admin/apis/{{.ModuleName}}"
"go-admin/app/admin/middleware" "go-admin/app/admin/middleware"
"go-admin/app/admin/models" "go-admin/app/admin/models"
"go-admin/app/admin/service/dto" "go-admin/app/admin/service/dto"
@@ -26,7 +25,7 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJW
})) }))
r.GET("/:id", actions.PermissionAction(), actions.ViewAction(new(dto.{{.ClassName}}ById))) r.GET("/:id", actions.PermissionAction(), actions.ViewAction(new(dto.{{.ClassName}}ById)))
r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control))) r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
r.PUT("", actions.PermissionAction(), actions.UpdateAction(new(dto.{{.ClassName}}Control))) r.PUT("/:id", actions.PermissionAction(), actions.UpdateAction(new(dto.{{.ClassName}}Control)))
r.DELETE("/:id", actions.PermissionAction(), actions.DeleteAction(new(dto.{{.ClassName}}ById))) r.DELETE("/:id", actions.PermissionAction(), actions.DeleteAction(new(dto.{{.ClassName}}ById)))
} }
} }
@@ -3,7 +3,10 @@ package router
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go-admin/apis/{{.ModuleName}}" "go-admin/app/admin/middleware"
"go-admin/app/admin/models"
"go-admin/app/admin/service/dto"
"go-admin/common/actions"
) )
// 无需认证的路由代码 // 无需认证的路由代码
@@ -17,7 +20,7 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup) {
})) }))
r.GET("/:id", actions.ViewAction(new(dto.{{.ClassName}}ById))) r.GET("/:id", actions.ViewAction(new(dto.{{.ClassName}}ById)))
r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control))) r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
r.PUT("", actions.UpdateAction(new(dto.{{.ClassName}}Control))) r.PUT("/:id", actions.UpdateAction(new(dto.{{.ClassName}}Control)))
r.DELETE("/:id", actions.DeleteAction(new(dto.{{.ClassName}}ById))) r.DELETE("/:id", actions.DeleteAction(new(dto.{{.ClassName}}ById)))
} }
} }
+6 -2
View File
@@ -215,7 +215,7 @@
</template> </template>
<script> <script>
import {add{{.ClassName}}, del{{.ClassName}}, get{{.ClassName}}, list{{.ClassName}}, update{{.ClassName}}} from '@/api/{{ .PackageName}}' import {add{{.ClassName}}, del{{.ClassName}}, get{{.ClassName}}, list{{.ClassName}}, update{{.ClassName}}} from '@/api/{{ .BusinessName}}'
{{range .Columns}} {{range .Columns}}
{{- if ne .FkTableName "" -}} {{- if ne .FkTableName "" -}}
import {list{{.FkTableNameClass}} } from '@/api/{{ .FkTableNamePackage}}' import {list{{.FkTableNameClass}} } from '@/api/{{ .FkTableNamePackage}}'
@@ -428,7 +428,11 @@
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(function () { }).then(function () {
return del{{.ClassName}}(Ids) if (Ids.length > 1) {
return del{{.ClassName}}(Ids.shift(), { 'ids': Ids })
} else {
return del{{.ClassName}}(Ids, { 'ids': [] })
}
}).then(() => { }).then(() => {
this.getList() this.getList()
this.msgSuccess('删除成功') this.msgSuccess('删除成功')
+34 -34
View File
@@ -1,47 +1,47 @@
package test package test
import ( import (
"go-admin/models/tools" //"go-admin/models/tools"
"os" //"os"
"testing" "testing"
"text/template" //"text/template"
) )
func TestGoModelTemplate(t *testing.T) { func TestGoModelTemplate(t *testing.T) {
t1, err := template.ParseFiles("model.go.template") //t1, err := template.ParseFiles("model.go.template")
if err != nil { //if err != nil {
t.Error(err) // t.Error(err)
} //}
table := tools.SysTables{} //table := tools.SysTables{}
table.TBName = "sys_tables" //table.TBName = "sys_tables"
tab, err := table.Get() //tab, err := table.Get()
if err != nil { //if err != nil {
t.Error(err) // t.Error(err)
} //}
file, err := os.Create("models/" + table.PackageName + ".go") //file, err := os.Create("models/" + table.PackageName + ".go")
if err != nil { //if err != nil {
t.Error(err) // t.Error(err)
} //}
defer file.Close() //defer file.Close()
//
_ = t1.Execute(file, tab) //_ = t1.Execute(file, tab)
t.Log("") t.Log("")
} }
func TestGoApiTemplate(t *testing.T) { func TestGoApiTemplate(t *testing.T) {
t1, err := template.ParseFiles("api.go.template") //t1, err := template.ParseFiles("api.go.template")
if err != nil { //if err != nil {
t.Error(err) // t.Error(err)
} //}
table := tools.SysTables{} //table := tools.SysTables{}
table.TBName = "sys_tables" //table.TBName = "sys_tables"
tab, _ := table.Get() //tab, _ := table.Get()
file, err := os.Create("apis/" + table.PackageName + ".go") //file, err := os.Create("apis/" + table.PackageName + ".go")
if err != nil { //if err != nil {
t.Error(err) // t.Error(err)
} //}
defer file.Close() //defer file.Close()
//
_ = t1.Execute(file, tab) //_ = t1.Execute(file, tab)
t.Log("") t.Log("")
} }
+4 -1
View File
@@ -34,7 +34,10 @@ func FileCreate(content bytes.Buffer, name string) {
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
file.WriteString(content.String()) _, err = file.WriteString(content.String())
if err != nil {
log.Println(err)
}
//for i := 0; i < len(content); i++ { //for i := 0; i < len(content); i++ {
// //写入byte的slice数据 // //写入byte的slice数据
// file.Write(content) // file.Write(content)