feat: skeleton
This commit is contained in:
30
internal/templates.go
Normal file
30
internal/templates.go
Normal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user