yt-gen-app/lib/backend-generate-rest.go
ymnuk 509b413d34
All checks were successful
continuous-integration/drone/tag Build is passing
Генерация функций REST на сервере
2023-08-17 23:21:09 +03:00

59 lines
2.0 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: i,
Rest: Project.Backend.Rest[i],
}
destPath := filepath.Join(AppConfig.OutdirBackend, "route", "api", 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)
}
}
}
}
}