Documentation
¶
Overview ¶
Package resourcegen implements `gombit make resource`.
It writes a feature-package (model, thin Huma handler, routes; optional service.go / repo.go), React list/form pages that import generated OpenAPI client types, and registers the package from cmd/server/main.go via go/ast. Generators are idempotent and additive; Go source is never patched with regular expressions.
Index ¶
- Constants
- func AddAutoMigrateModel(src []byte, importPath, pkgName, typeName string) ([]byte, error)
- func AddImportAndRegister(src []byte, importPath, pkgName string) ([]byte, error)
- func CollectAutoMigrateModels(src []byte) ([]migrations.Model, error)
- func CountRegisterCalls(src []byte, pkgName string) (int, error)
- func Generate(ctx context.Context, opts Options) error
- type Field
- type FieldType
- type Options
- type ResourceName
Constants ¶
const ( // GeneratedBanner marks files written by this generator. User-owned files // without the banner are refused unless --force is set. Identical re-runs // rewrite the same bytes (idempotent). GeneratedBanner = "Code generated by gombit make resource. DO NOT EDIT." )
Variables ¶
This section is empty.
Functions ¶
func AddAutoMigrateModel ¶
AddAutoMigrateModel adds `&<pkg>.<type>{}` to the AutoMigrate call in internal/platform and ensures importPath is imported. Idempotent.
func AddImportAndRegister ¶
AddImportAndRegister adds `importPath` and `<pkg>.Register(app)` next to an existing `*.Register(app)` call (the scaffold's product.Register) or, if none exists, immediately before `framework.Run(app)` — including the `if err := framework.Run(app); err != nil` form used by the app template. The edit is idempotent: a second call does not duplicate the import or the Register invocation.
func CollectAutoMigrateModels ¶
func CollectAutoMigrateModels(src []byte) ([]migrations.Model, error)
CollectAutoMigrateModels returns every `&pkg.Type{}` argument of AutoMigrate calls in src, resolved to import path + type name via the file's imports. Atlas migrate diff treats that slice as the entire desired schema, so callers must pass every registered model — not only the resource being generated.
func CountRegisterCalls ¶
CountRegisterCalls reports how many `<pkg>.Register(...)` calls appear in src.
Types ¶
type Field ¶
type Field struct {
Name string
JSONName string
GoName string
Type FieldType
GoType string
Required bool
Unique bool
Index bool
Nullable bool
// Filterable / Sortable / Searchable opt this field into the generated list
// handler's declared query surface (issue #260): exact-match ?<field>=,
// ?ordering=<field> (- prefix for DESC), and ?search= respectively — the same
// spelling as the admin data plane. belongs_to fields are filterable by
// default (see isFilterable) so the has_many detail-list case —
// GET /children?<parent>_id=<id> — works without extra declaration.
Filterable bool
Sortable bool
Searchable bool
// Aggregatable opts this numeric field into the generated list handler's
// server-side aggregate surface (issue #272): ?aggregate=sum:<field>,
// avg:<field>,min:<field>,max:<field>, computed over the same filtered and
// searched set as the list, before pagination. Only numeric columns (int,
// int64, uint, decimal) may opt in (see typeAllowsAggregate).
Aggregatable bool
// EnumValues holds the allowed values for FieldEnum, in declared order.
EnumValues []string
// Precision/Scale set the decimal(p,s) column for FieldDecimal.
Precision int
Scale int
// Target is the related model type (PascalCase) for a relation field, e.g.
// "Engine". TargetPkg is its feature-package name (snake), e.g. "engine".
Target string
TargetPkg string
}
Field is one parsed resource field from the CLI grammar name:type[:required][,unique][,index] (design §27 subset).
type FieldType ¶
type FieldType string
FieldType is a supported scalar in the v0.1 subset.
const ( FieldString FieldType = "string" FieldText FieldType = "text" FieldInt FieldType = "int" FieldInt64 FieldType = "int64" FieldBool FieldType = "bool" FieldUint FieldType = "uint" FieldDecimal FieldType = "decimal" FieldTime FieldType = "time" FieldEnum FieldType = "enum" FieldBelongsTo FieldType = "belongs_to" FieldHasMany FieldType = "has_many" FieldManyToMany FieldType = "many_to_many" )