controllers

package
v1.0.0-beta.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ResourceName        string
	PluralName          string
	TableName           string
	PackageName         string
	ModulePath          string
	ControllerType      ControllerType
	TableNameOverridden bool
	PrimaryKeyColumn    string // Override PK column name (empty = auto-detect)
	Actions             []string
}

type ControllerType

type ControllerType int
const (
	ResourceController ControllerType = iota
	ResourceControllerNoViews
	NormalController
)

type FileGenerator

type FileGenerator struct {
	// contains filtered or unexported fields
}

func NewFileGenerator

func NewFileGenerator() *FileGenerator

func (*FileGenerator) GenerateController

func (fg *FileGenerator) GenerateController(
	cat *catalog.Catalog,
	resourceName string,
	tableName string,
	controllerType ControllerType,
	modulePath string,
	databaseType string,
	tableNameOverridden bool,
	nullType string,
	primaryKeyColumn string,
	diMode string,
	inertia string,
) error

func (*FileGenerator) GenerateControllerWithActions

func (fg *FileGenerator) GenerateControllerWithActions(
	cat *catalog.Catalog,
	resourceName string,
	tableName string,
	controllerType ControllerType,
	modulePath string,
	databaseType string,
	tableNameOverridden bool,
	nullType string,
	primaryKeyColumn string,
	diMode string,
	inertia string,
	actions []string,
) error

type FragmentInjector

type FragmentInjector struct {
	// contains filtered or unexported fields
}

FragmentInjector handles injecting fragment code into existing controller, route, and connect files.

func NewFragmentInjector

func NewFragmentInjector() *FragmentInjector

NewFragmentInjector creates a new FragmentInjector.

func (*FragmentInjector) InjectControllerMethod

func (fi *FragmentInjector) InjectControllerMethod(controllerPath string, data FragmentMethodData) error

InjectControllerMethod appends a method stub to the end of the controller file. It checks for duplicate methods before injecting.

func (*FragmentInjector) InjectRouteRegistration

func (fi *FragmentInjector) InjectRouteRegistration(connectPath string, data FragmentRegistrationData) error

InjectRouteRegistration inserts a route registration block before the "return errors.Join(errs...)" marker in the connect file. If the marker is not found, it prints manual instructions.

func (*FragmentInjector) InjectRouteVariable

func (fi *FragmentInjector) InjectRouteVariable(routesPath string, data FragmentRouteData) error

InjectRouteVariable appends a route variable declaration to the end of the routes file. It checks for duplicate route variables before injecting.

type FragmentMethodData

type FragmentMethodData struct {
	ReceiverName       string
	PluralResourceName string
	MethodName         string
}

FragmentMethodData holds data for rendering the fragment_method.tmpl template.

type FragmentRegistrationData

type FragmentRegistrationData struct {
	ResourceName string
	MethodName   string
	HTTPMethod   string
	HandlerVar   string
}

FragmentRegistrationData holds data for rendering the fragment_route_registration.tmpl template.

type FragmentRouteData

type FragmentRouteData struct {
	ResourceName    string
	MethodName      string
	ConstructorName string
	ParamsStruct    string // non-empty for RouteWithSlugs: the generated params struct definition
	Path            string
	PluralName      string
	LowerMethodName string
}

FragmentRouteData holds data for rendering the fragment_route.tmpl template.

type FxInjector

type FxInjector struct {
	// contains filtered or unexported fields
}

func NewFxInjector

func NewFxInjector() *FxInjector

func (*FxInjector) InjectController

func (fi *FxInjector) InjectController(resourceName, pluralName string) error

type GeneratedController

type GeneratedController struct {
	ResourceName        string
	PluralName          string
	PluralResourceName  string // The pluralized form of ResourceName (respects --table-name override)
	ReceiverName        string // Short receiver name for methods (e.g., "sf" for StudentFeedback)
	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
}

type GeneratedField

type GeneratedField struct {
	Name          string
	GoType        string
	GoFormType    string
	DBName        string
	CamelCase     string
	IsSystemField bool
	IsPointer     bool
}

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator(databaseType string) *Generator

func (*Generator) Build

func (g *Generator) Build(cat *catalog.Catalog, config Config) (*GeneratedController, error)

func (*Generator) SetNullType added in v1.0.0

func (g *Generator) SetNullType(nullType string)

type MainInjector added in v1.0.0

type MainInjector struct {
	// contains filtered or unexported fields
}

func NewMainInjector added in v1.0.0

func NewMainInjector() *MainInjector

func (*MainInjector) InjectController added in v1.0.0

func (mi *MainInjector) InjectController(resourceName, pluralName string) error

InjectController adds controller constructor and registration to main.go Returns nil if marker not found (logs info message instead of failing)

func (*MainInjector) InjectFXController

func (mi *MainInjector) InjectFXController(resourceName, pluralName string) error

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

func NewRouteGenerator

func NewRouteGenerator() *RouteGenerator

func (*RouteGenerator) GenerateRoutes

func (rg *RouteGenerator) GenerateRoutes(resourceName, pluralName, idType, diMode string) error

func (*RouteGenerator) GenerateRoutesWithActions

func (rg *RouteGenerator) GenerateRoutesWithActions(resourceName, pluralName, idType, diMode string, actions []string) error

type RouteType added in v1.0.0

type RouteType int

RouteType represents the type of route constructor to use

const (
	SimpleRoute RouteType = iota
	RouteWithID
	RouteWithSlug
	RouteWithToken
	RouteWithFile
	RouteWithSlugs
)

func DetectRouteType added in v1.0.0

func DetectRouteType(path string) RouteType

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

func (rt RouteType) ConstructorName(idType, paramsTypeName string) string

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
}

func NewTemplateRenderer

func NewTemplateRenderer() *TemplateRenderer

func (*TemplateRenderer) RenderControllerFile

func (tr *TemplateRenderer) RenderControllerFile(controller *GeneratedController, diMode, inertia string) (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL