feat: skeleton

This commit is contained in:
2025-01-04 23:23:44 +07:00
commit 50979ed70e
10 changed files with 308 additions and 0 deletions

30
internal/templates.go Normal file
View File

@@ -0,0 +1,30 @@
package internal
import (
"strings"
)
type CrudTemplateContext struct {
ServiceName string
EntityType string
EntityPlural string
}
var ServiceImports = []string{
"app/internal/dal",
"app/internal/models",
//"errors"
"gorm.io/gen/field",
//"gorm.io/gorm"
}
var GetAllRawTemplate = `func (service *{{.ServiceName}}) GetAll() ([]*{{.EntityType}}, error) {
var {{.EntityPlurar}} []*{{.EntityType}}
{{.EntityPlural}}, err := dal.{{.EntityType}}.Preload(field.Associations).Find()
return {{.EntityPlural}}, err
}`
func ToPlural(entityName string) string {
return strings.ToLower(entityName) + "s"
}