yt-gen-app/lib/backend-generate-rest.go

61 lines
2.1 KiB
Go

package lib
import (
"fmt"
"log"
"path/filepath"
"git.ymnuktech.ru/ymnuk/yt-gen-app/lib/templ"
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
)
func generateBackendRest() {
/*type RestStruct struct {
Path string
Project *structs.Project
Rest *structs.Rest
}*/
if len(Project.Backend.Rest) > 0 {
for i := range Project.Backend.Rest {
restStruct := &structs.RestStruct{
Project: Project,
Path: templ.ParseRestPath(i),
PathPackageName: templ.ParseRestPathForName(i),
Rest: Project.Backend.Rest[i],
PathParams: templ.ParseRestPathParams(i),
}
destPath := filepath.Join(AppConfig.OutdirBackend, "route", "api", templ.BackendFsPath(i))
fmt.Println(destPath)
if err := templ.PrepareTmplFile("tmpl/backend/route/api/templ/index.tmpl", restStruct, filepath.Join(destPath, "index.go")); err != nil {
log.Fatal(err)
}
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/list.tmpl", restStruct, filepath.Join(destPath, "list.go")); err != nil {
log.Fatal(err)
}
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/count.tmpl", restStruct, filepath.Join(destPath, "count.go")); err != nil {
log.Fatal(err)
}
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/get.tmpl", restStruct, filepath.Join(destPath, "get.go")); err != nil {
log.Fatal(err)
}
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/search.tmpl", restStruct, filepath.Join(destPath, "search.go")); err != nil {
log.Fatal(err)
}
if Project.Backend.Rest[i].Editable {
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/post.tmpl", restStruct, filepath.Join(destPath, "post.go")); err != nil {
log.Fatal(err)
}
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/put.tmpl", restStruct, filepath.Join(destPath, "put.go")); err != nil {
log.Fatal(err)
}
if err := templ.PrepareTmplIsNotExists("tmpl/backend/route/api/templ/delete.tmpl", restStruct, filepath.Join(destPath, "delete.go")); err != nil {
log.Fatal(err)
}
}
}
}
}