Documentation
¶
Overview ¶
Package controllers generates controller and route source files from resource metadata.
Index ¶
- func ExistingRouteFileActions(routesPath, resourceName, namespace, pluralName string) ([]string, error)
- type ActionInjector
- func (ai *ActionInjector) InjectControllerMethod(controllerPath string, data ActionMethodData) error
- func (ai *ActionInjector) InjectRouteRegistration(controllerPath string, data ActionRegistrationData) error
- func (ai *ActionInjector) InjectRouteVariable(routesPath string, data ActionRouteData) error
- type ActionMethodData
- type ActionRegistrationData
- type ActionRouteData
- type Config
- type ControllerType
- type FileGenerator
- type GeneratedController
- type GeneratedField
- type Generator
- type MainInjector
- type RouteGenerator
- type RouteType
- type TemplateRenderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExistingRouteFileActions ¶ added in v1.2.2
func ExistingRouteFileActions(routesPath, resourceName, namespace, pluralName string) ([]string, error)
ExistingRouteFileActions returns the resource actions declared in a generated route file.
Types ¶
type ActionInjector ¶ added in v1.0.0
type ActionInjector struct {
// contains filtered or unexported fields
}
ActionInjector handles injecting action code into existing controller and route files.
func NewActionInjector ¶ added in v1.0.0
func NewActionInjector() *ActionInjector
NewActionInjector creates a new ActionInjector.
func (*ActionInjector) InjectControllerMethod ¶ added in v1.0.0
func (ai *ActionInjector) InjectControllerMethod(controllerPath string, data ActionMethodData) error
InjectControllerMethod appends a method stub to the end of the controller file. It checks for duplicate methods before injecting.
func (*ActionInjector) InjectRouteRegistration ¶ added in v1.0.0
func (ai *ActionInjector) InjectRouteRegistration(controllerPath string, data ActionRegistrationData) error
InjectRouteRegistration inserts a route registration block before the final error return in the controller RegisterRoutes method. If the return statement is not found, it prints manual instructions.
func (*ActionInjector) InjectRouteVariable ¶ added in v1.0.0
func (ai *ActionInjector) InjectRouteVariable(routesPath string, data ActionRouteData) error
InjectRouteVariable appends a route variable declaration to the end of the routes file. It checks for duplicate route variables before injecting.
type ActionMethodData ¶ added in v1.0.0
ActionMethodData holds data for rendering the action_method.tmpl template.
type ActionRegistrationData ¶ added in v1.0.0
type ActionRegistrationData struct {
ResourceName string
Namespace string
NamespacePascal string
MethodName string
HTTPMethod string
HandlerVar string
}
ActionRegistrationData holds data for rendering the action_registration.tmpl template.
type ActionRouteData ¶ added in v1.0.0
type ActionRouteData struct {
ResourceName string
Namespace string
NamespacePascal string
MethodName string
ConstructorName string
ParamsStruct string // non-empty for RouteWithSlugs: the generated params struct definition
Path string
PluralName string
LowerMethodName string
}
ActionRouteData holds data for rendering the action_route.tmpl template.
type Config ¶
type Config struct {
ResourceName string
ModelName string
PluralName string
ModelPluralName string
TableName string
ModelTableName string
Namespace string
PackageName string
ModulePath string
ControllerType ControllerType
TableNameOverridden bool
ModelTableNameOverridden bool
PrimaryKeyColumn string // Override PK column name (empty = auto-detect)
Actions []string
IsAPI bool // Controller is JSON API
}
Config controls controller generation for a resource.
type ControllerType ¶
type ControllerType int
ControllerType identifies the shape of controller being generated.
const ( // ResourceController generates a REST-style resource controller. ResourceController ControllerType = iota // NormalController generates a non-resource controller. NormalController )
type FileGenerator ¶
type FileGenerator struct {
// contains filtered or unexported fields
}
FileGenerator generates file artifacts.
func NewFileGenerator ¶
func NewFileGenerator() *FileGenerator
NewFileGenerator creates a new file generator.
func (*FileGenerator) GenerateController ¶
func (fg *FileGenerator) GenerateController( cat *catalog.Catalog, resourceName string, namespace string, tableName string, controllerType ControllerType, modulePath string, databaseType string, tableNameOverridden bool, nullType string, primaryKeyColumn string, inertia string, ) error
GenerateController performs the generate controller operation.
func (*FileGenerator) GenerateControllerWithActionsForModel ¶ added in v1.0.0
func (fg *FileGenerator) GenerateControllerWithActionsForModel( cat *catalog.Catalog, resourceName string, namespace string, modelName string, tableName string, modelTableName string, controllerType ControllerType, modulePath string, databaseType string, tableNameOverridden bool, modelTableNameOverridden bool, nullType string, primaryKeyColumn string, inertia string, actions []string, isAPI bool, ) error
GenerateControllerWithActionsForModel performs the generate controller with actions for model operation.
type GeneratedController ¶
type GeneratedController struct {
ResourceName string
ModelName string
PluralName string
ModelPluralName string
PluralResourceName string // The pluralized form of ResourceName (respects --table-name override)
ModelPluralResourceName string
ReceiverName string // Short receiver name for methods (e.g., "sf" for StudentFeedback)
Namespace string // "admin" (empty if no namespace)
NamespacePascal string // "Admin" (PascalCase for prefixing)
Package string
Fields []GeneratedField
ModulePath string
Type ControllerType
DatabaseType string
TableNameOverridden bool
IDType string // "uuid.UUID", "int32", "int64", "string"
IsAutoIncrementID bool // True for serial/bigserial
IDGoFieldName string // Go struct field name of PK (e.g., "ID", "UserID")
HasPrimaryKey bool // Whether the table has any primary key
Actions []string
IsAPI bool // Generate JSON API controller under controllers/api
}
GeneratedController contains the template data for generated controllers.
type GeneratedField ¶
type GeneratedField struct {
Name string
GoType string
GoFormType string
DBName string
CamelCase string
IsSystemField bool
IsPointer bool
}
GeneratedField describes one controller field derived from a database column.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator builds controller template data and writes controller files.
func NewGenerator ¶
NewGenerator creates a new generator.
func (*Generator) Build ¶
Build converts catalog metadata and config into generated controller data.
func (*Generator) SetNullType ¶ added in v1.0.0
SetNullType sets null type.
type MainInjector ¶ added in v1.0.0
type MainInjector struct {
// contains filtered or unexported fields
}
MainInjector represents main injector.
func NewMainInjector ¶ added in v1.0.0
func NewMainInjector() *MainInjector
NewMainInjector creates a new main injector.
func (*MainInjector) InjectController ¶ added in v1.0.0
func (mi *MainInjector) InjectController(resourceName, namespace, pluralName string) error
InjectController adds a generated resource controller to controllers.Module. Returns nil if the file or expected module shape is not found, after printing instructions for a manual update.
type RouteGenerator ¶
type RouteGenerator struct {
// contains filtered or unexported fields
}
RouteGenerator generates route artifacts.
func NewRouteGenerator ¶
func NewRouteGenerator() *RouteGenerator
NewRouteGenerator creates a new route generator.
func (*RouteGenerator) GenerateRoutes ¶
func (rg *RouteGenerator) GenerateRoutes(resourceName, namespace, pluralName, idType string, actions []string) error
GenerateRoutes performs the generate routes operation.
type RouteType ¶ added in v1.0.0
type RouteType int
RouteType represents the type of route constructor to use
const ( // SimpleRoute is a constant value for simple route. SimpleRoute RouteType = iota // RouteWithID is a constant value for route with i d. RouteWithID // RouteWithSlug is a constant value for route with slug. RouteWithSlug // RouteWithToken is a constant value for route with token. RouteWithToken // RouteWithFile is a constant value for route with file. RouteWithFile // RouteWithSlugs is a constant value for route with slugs. RouteWithSlugs )
func DetectRouteType ¶ added in v1.0.0
DetectRouteType analyzes a path string and returns the appropriate RouteType. It inspects path segments for :param patterns and maps them to routing constructors.
func (RouteType) ConstructorName ¶ added in v1.0.0
ConstructorName returns the routing package constructor function name for this RouteType. For RouteWithID, the idType parameter selects the appropriate type-specific constructor. For RouteWithSlugs, paramsTypeName is the generated params struct name used as the type parameter.
type TemplateRenderer ¶
type TemplateRenderer struct {
// contains filtered or unexported fields
}
TemplateRenderer represents template renderer.
func NewTemplateRenderer ¶
func NewTemplateRenderer() *TemplateRenderer
NewTemplateRenderer creates a new template renderer.
func (*TemplateRenderer) RenderControllerFile ¶
func (tr *TemplateRenderer) RenderControllerFile(controller *GeneratedController, inertia string) (string, error)
RenderControllerFile performs the render controller file operation.