57 lines
1.9 KiB
Go
57 lines
1.9 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 := &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/delete.tmpl", restStruct, filepath.Join(destPath, "delete.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/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/search.tmpl", restStruct, filepath.Join(destPath, "search.go")); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
}
|