This repository has been archived on 2025-03-16. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
crudgen/internal/templates.go
2025-01-04 23:23:44 +07:00

31 lines
619 B
Go

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"
}