Documentation
¶
Overview ¶
Package blueprint provides structured types for scaffold configuration that support additive merges from multiple extensions without conflicts.
Index ¶
- type BackgroundWorker
- type Blueprint
- type Builder
- func (b *Builder) AddBackgroundWorker(name, functionCall string, dependsOn ...string) *Builder
- func (b *Builder) AddConfigField(name, typeName string) *Builder
- func (b *Builder) AddControllerConstructor(varName, expression string) *Builder
- func (b *Builder) AddControllerDependency(name, typeName string) *Builder
- func (b *Builder) AddControllerDependencyWithInit(name, typeName, initExpr string) *Builder
- func (b *Builder) AddControllerField(name, typeName string) *Builder
- func (b *Builder) AddControllerImport(importPath string) *Builder
- func (b *Builder) AddEnvVar(key, configField, defaultValue string) *Builder
- func (b *Builder) AddMainImport(importPath string) *Builder
- func (b *Builder) AddMainInitialization(varName, expression string, dependsOn ...string) *Builder
- func (b *Builder) AddMigration(migration Migration) *Builder
- func (b *Builder) AddModel(model Model) *Builder
- func (b *Builder) AddModelImport(importPath string) *Builder
- func (b *Builder) AddPreRunHook(name, code string) *Builder
- func (b *Builder) AddRoute(route Route) *Builder
- func (b *Builder) AddRouteCollection(routes ...string) *Builder
- func (b *Builder) AddRouteGroup(groupName string) *Builder
- func (b *Builder) AddRouteImport(importPath string) *Builder
- func (b *Builder) AddRouteRegistration(method, routeVariable, controllerRef string, middleware ...string) *Builder
- func (b *Builder) AddTool(tool string) *Builder
- func (b *Builder) Blueprint() *Blueprint
- func (b *Builder) EndRouteRegistrationFunction() *Builder
- func (b *Builder) Merge(other *Blueprint) error
- func (b *Builder) StartRouteRegistrationFunction(functionName string) *Builder
- type ConfigSection
- type Constructor
- type ControllerSection
- type Dependency
- type EnvVar
- type Field
- type Initialization
- type MainSection
- type Migration
- type MigrationSection
- type Model
- type ModelSection
- type OrderedSet
- type PreRunHook
- type RegistrationFunction
- type Route
- type RouteCollection
- type RouteRegistration
- type RouteSection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackgroundWorker ¶
type BackgroundWorker struct {
// Name is a descriptive name for the worker
Name string
// FunctionCall is the function to call (e.g., "worker.StartQueue(ctx, queue)")
FunctionCall string
// DependsOn lists variables this worker needs
DependsOn []string
// Order for deterministic rendering
Order int
}
BackgroundWorker represents a goroutine to start in main.go
type Blueprint ¶
type Blueprint struct {
// Tools lists go tool dependencies for the go.mod tool directive
Tools *OrderedSet
// Controllers section
Controllers ControllerSection
// Routes section
Routes RouteSection
// Models section
Models ModelSection
// Configuration section
Config ConfigSection
// Migrations and database
Migrations MigrationSection
// Main holds configuration for the main.go application setup
Main MainSection
}
Blueprint holds all structured configuration for a scaffold project. Each section supports additive operations that maintain uniqueness and ordering.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a typed API for adding elements to a blueprint while enforcing uniqueness and maintaining deterministic ordering.
func NewBuilder ¶
NewBuilder creates a builder wrapping the provided blueprint.
func (*Builder) AddBackgroundWorker ¶
AddBackgroundWorker adds a background worker goroutine to main.go.
func (*Builder) AddConfigField ¶
AddConfigField adds a field to the config struct.
func (*Builder) AddControllerConstructor ¶
AddControllerConstructor adds a constructor initialization statement. The fieldName is automatically derived by finding a matching controller field. If no match is found, it capitalizes the first letter of varName. TODO: naming
func (*Builder) AddControllerDependency ¶
AddControllerDependency adds a dependency parameter to the controller constructor. The order is automatically assigned based on insertion sequence. Use AddControllerDependencyWithInit to provide an initialization expression.
func (*Builder) AddControllerDependencyWithInit ¶
AddControllerDependencyWithInit adds a dependency with an optional initialization expression. If initExpr is provided, it will be used to initialize the dependency in main.go. If initExpr is empty, the dependency is assumed to be provided externally (like db).
func (*Builder) AddControllerField ¶
AddControllerField adds a field to the Controllers struct.
func (*Builder) AddControllerImport ¶
AddControllerImport adds an import path to the controllers section.
func (*Builder) AddMainImport ¶
AddMainImport adds an import path to the main.go file.
func (*Builder) AddMainInitialization ¶
AddMainInitialization adds an initialization code block to main.go. The varName is the variable name, expression is the initialization code. DependsOn can be used to specify ordering dependencies.
func (*Builder) AddMigration ¶
AddMigration adds a migration definition.
func (*Builder) AddModelImport ¶
AddModelImport adds an import to the models section.
func (*Builder) AddPreRunHook ¶
AddPreRunHook adds a pre-run hook to execute before the server starts.
func (*Builder) AddRouteCollection ¶
AddRouteCollection records route expressions to include in the BuildRoutes literal.
func (*Builder) AddRouteGroup ¶
AddRouteGroup adds a route group name (e.g., "auth" for authRoutes). These are used by the router aggregator template to combine all route groups.
func (*Builder) AddRouteImport ¶
AddRouteImport adds an import to the routes section.
func (*Builder) AddRouteRegistration ¶
func (b *Builder) AddRouteRegistration(method, routeVariable, controllerRef string, middleware ...string) *Builder
AddRouteRegistration adds a route registration entry for the registrar function. The method is the HTTP method constant (e.g., "http.MethodGet"), routeVariable is the route variable (e.g., "routes.Health"), controllerRef is the controller method reference (e.g., "ctrls.API.Health"), and middleware is optional middleware to apply. If a registration function is currently being built (via StartRouteRegistrationFunction), the registration is added to that function. Otherwise, it's added to the main registrations.
func (*Builder) AddTool ¶
AddTool registers a go tool binary to include in the go.mod tool directive.
func (*Builder) EndRouteRegistrationFunction ¶
EndRouteRegistrationFunction completes the current registration function and adds it to the blueprint.
func (*Builder) Merge ¶
Merge combines another blueprint into this one, maintaining uniqueness and order. Items from the other blueprint are added after existing items.
func (*Builder) StartRouteRegistrationFunction ¶
StartRouteRegistrationFunction begins building a registration function. All subsequent AddRouteRegistration calls will be added to this function until EndRouteRegistrationFunction is called.
type ConfigSection ¶
type ConfigSection struct {
// Config struct fields
Fields []Field
// Environment variable mappings
EnvVars []EnvVar
}
ConfigSection holds application configuration.
func (*ConfigSection) SortedEnvVars ¶
func (cs *ConfigSection) SortedEnvVars() []EnvVar
SortedEnvVars returns environment variables sorted by order.
func (*ConfigSection) SortedFields ¶
func (cs *ConfigSection) SortedFields() []Field
SortedFields returns config fields sorted by order.
type Constructor ¶
type Constructor struct {
// VarName is the variable name on the left side (e.g., "pages")
VarName string
// FieldName is the struct field this variable should be assigned to (e.g., "Pages")
FieldName string
// Expression is the right-hand side (e.g., "newPages(db, cache)")
Expression string
// Order for deterministic rendering
Order int
}
Constructor represents an initialization statement in a constructor.
type ControllerSection ¶
type ControllerSection struct {
// Import paths needed by controllers
Imports *OrderedSet
// Controller dependencies (parameters for New function)
Dependencies []Dependency
// Controller fields to add to the Controllers struct
Fields []Field
// Constructor initializations (e.g., "pages := newPages(db, cache)")
Constructors []Constructor
}
ControllerSection holds controller-related configuration.
func (*ControllerSection) SortedConstructors ¶
func (cs *ControllerSection) SortedConstructors() []Constructor
SortedConstructors returns constructors sorted by order.
func (*ControllerSection) SortedDependencies ¶
func (cs *ControllerSection) SortedDependencies() []Dependency
SortedDependencies returns controller dependencies sorted by order.
func (*ControllerSection) SortedFields ¶
func (cs *ControllerSection) SortedFields() []Field
SortedFields returns controller fields sorted by order.
type Dependency ¶
type Dependency struct {
Name string
Type string
// InitExpr is the optional initialization expression (e.g., "queue.NewInMemoryQueue()")
// If empty, the dependency is assumed to be provided externally (like db)
InitExpr string
// ImportPath is the import path needed when InitExpr is provided
// (e.g., "myapp/queue" for "queue.NewInMemoryQueue()")
ImportPath string
// Order for deterministic rendering
Order int
}
Dependency represents a constructor parameter.
type EnvVar ¶
type EnvVar struct {
Key string
ConfigField string
DefaultValue string
// Order for deterministic rendering
Order int
}
EnvVar represents an environment variable mapping.
type Initialization ¶
type Initialization struct {
// VarName is the variable name (e.g., "emailSender")
VarName string
// Expression is the initialization code (e.g., "email.NewMailpit()")
Expression string
// DependsOn lists variable names this depends on (for ordering)
DependsOn []string
// Order for deterministic rendering
Order int
}
Initialization represents a service/dependency initialization in main.go
type MainSection ¶
type MainSection struct {
// Import paths needed in main.go (beyond controller dependencies)
Imports *OrderedSet
// Initialization code blocks (e.g., service creation)
Initializations []Initialization
// Background workers to start
BackgroundWorkers []BackgroundWorker
// Pre-run hooks executed before server starts
PreRunHooks []PreRunHook
}
MainSection holds application startup configuration.
func (*MainSection) SortedBackgroundWorkers ¶
func (ms *MainSection) SortedBackgroundWorkers() []BackgroundWorker
SortedBackgroundWorkers returns background workers sorted by order.
func (*MainSection) SortedInitializations ¶
func (ms *MainSection) SortedInitializations() []Initialization
SortedInitializations returns initializations sorted by order.
func (*MainSection) SortedPreRunHooks ¶
func (ms *MainSection) SortedPreRunHooks() []PreRunHook
SortedPreRunHooks returns pre-run hooks sorted by order.
type Migration ¶
type Migration struct {
Name string
Timestamp string
Path string
// Order for deterministic rendering (usually by timestamp)
Order int
}
Migration represents a database migration.
type MigrationSection ¶
type MigrationSection struct {
// Migration file paths
Migrations []Migration
}
MigrationSection holds database migration information.
func (*MigrationSection) SortedMigrations ¶
func (ms *MigrationSection) SortedMigrations() []Migration
SortedMigrations returns migrations sorted by order.
type ModelSection ¶
type ModelSection struct {
// Model imports
Imports *OrderedSet
// Model struct definitions
Models []Model
}
ModelSection holds model configuration.
func (*ModelSection) SortedModels ¶
func (ms *ModelSection) SortedModels() []Model
SortedModels returns models sorted by order.
type OrderedSet ¶
type OrderedSet struct {
// contains filtered or unexported fields
}
OrderedSet maintains a collection of unique strings in insertion order with optional canonical sorting.
func (*OrderedSet) Add ¶
func (os *OrderedSet) Add(item string) bool
Add inserts an item into the set if not already present. Returns true if the item was added, false if it already existed.
func (*OrderedSet) Contains ¶
func (os *OrderedSet) Contains(item string) bool
Contains reports whether the item is in the set.
func (*OrderedSet) Items ¶
func (os *OrderedSet) Items() []string
Items returns a copy of the current items in insertion order.
func (*OrderedSet) Len ¶
func (os *OrderedSet) Len() int
Len returns the number of unique items in the set.
func (*OrderedSet) Merge ¶
func (os *OrderedSet) Merge(other *OrderedSet)
Merge adds all items from another ordered set while maintaining uniqueness.
func (*OrderedSet) SortedItems ¶
func (os *OrderedSet) SortedItems() []string
SortedItems returns a sorted copy of the items.
type PreRunHook ¶
type PreRunHook struct {
// Name is a descriptive name for the hook
Name string
// Code is the Go code to execute (e.g., "if err := migrate(db); err != nil { return err }")
Code string
// Order for deterministic rendering
Order int
}
PreRunHook represents setup code to run before starting the server
type RegistrationFunction ¶
type RegistrationFunction struct {
// FunctionName is the name of the registration function (e.g., "registerAuthRoutes")
FunctionName string
// Registrations contains all route registrations for this function
Registrations []RouteRegistration
// Order for deterministic rendering
Order int
}
RegistrationFunction represents a named registration function that groups route registrations.
type Route ¶
type Route struct {
Name string
Path string
Controller string
ControllerMethod string
Method string
IncludeInSitemap bool
// Order for deterministic rendering
Order int
}
Route represents a route definition.
type RouteCollection ¶
RouteCollection represents grouped route variables for BuildRoutes.
type RouteRegistration ¶
type RouteRegistration struct {
// Method is the HTTP method (e.g., "http.MethodGet")
Method string
// RouteVariable is the route variable name (e.g., "routes.Health")
RouteVariable string
// ControllerRef is the controller method reference (e.g., "ctrls.API.Health")
ControllerRef string
// Middleware is optional middleware to apply to this route
Middleware []string
// Order for deterministic rendering
Order int
}
RouteRegistration represents a route registration entry for the registrar function.
type RouteSection ¶
type RouteSection struct {
// Route definitions
Routes []Route
// Route groups (e.g., "auth" for authRoutes, "admin" for adminRoutes)
// Used to aggregate routes in the router_routes_routes.tmpl aggregator
RouteGroups *OrderedSet
// RouteCollections holds grouped route expressions to include in BuildRoutes.
RouteCollections []RouteCollection
// Route group imports (for middleware, etc.)
Imports *OrderedSet
// RouteRegistrations holds route registration entries for the registrar function
Registrations []RouteRegistration
// RegistrationFunctions holds grouped registration functions
RegistrationFunctions []RegistrationFunction
}
RouteSection holds routing configuration.
func (*RouteSection) SortedRegistrationFunctions ¶
func (rs *RouteSection) SortedRegistrationFunctions() []RegistrationFunction
SortedRegistrationFunctions returns registration functions sorted by order.
func (*RouteSection) SortedRegistrations ¶
func (rs *RouteSection) SortedRegistrations() []RouteRegistration
SortedRegistrations returns route registrations sorted by order.
func (*RouteSection) SortedRouteCollections ¶
func (rs *RouteSection) SortedRouteCollections() []RouteCollection
SortedRouteCollections returns grouped route expressions sorted by order.
func (*RouteSection) SortedRoutes ¶
func (rs *RouteSection) SortedRoutes() []Route
SortedRoutes returns routes sorted by order.