Documentation
¶
Index ¶
- func CSSHelpers() template.FuncMap
- func GenerateAPI(basePath, moduleName, resourceName string, fields []parser.Field, ...) error
- func GenerateApp(appName, moduleName, kit, stylesAdapter string, devMode bool) error
- func GenerateAuth(projectRoot string, authConfig *AuthConfig) error
- func GenerateAuthz(projectRoot string, cfg *AuthzConfig) error
- func GenerateJob(projectRoot string, moduleName string, jobName string) error
- func GenerateQueue(projectRoot string, moduleName string) error
- func GenerateResource(basePath, moduleName, resourceName string, fields []parser.Field, ...) error
- func GenerateSchema(basePath, moduleName, tableName string, fields []parser.Field, ...) error
- func GenerateTask(projectRoot, moduleName, taskName, schedule string) error
- func GenerateView(basePath, moduleName, viewName string, kitName, cssFramework string) error
- func InjectAPIRegistration(mainGoPath, importPath string) error
- func InjectEmbeddedChild(parentGoPath string, childData ResourceData) error
- func InjectEmbeddedChildTemplate(parentTmplPath string, childData ResourceData) error
- func InjectRoute(mainGoPath string, route RouteInfo) error
- func ProtectResources(projectRoot, _ string, resources []ResourceEntry) error
- func ReadDevMode(basePath string) bool
- func RegisterResource(basePath, name, path, resourceType string) error
- func Singularize(word string) string
- func ToCamelCase(s string) string
- func UpdateResourceTestsForAuth(projectRoot string) error
- func ValidateTemplate(path string) error
- func WrapExistingRoutesWithAuth(mainGoPath string, structName string) error
- func WriteResources(basePath string, resources []ResourceEntry) error
- type APIData
- type AppData
- type AuthConfig
- type AuthzConfig
- type ComponentUsage
- type FieldData
- type JobConfig
- type JobsConfig
- type ResourceData
- type ResourceEntry
- type RouteInfo
- type TaskConfig
- type ViewData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CSSHelpers ¶
CSSHelpers returns template functions for CSS framework selection Only Tailwind and None are supported - Bulma and Pico have been removed for simplification
func GenerateAPI ¶
func GenerateAPI(basePath, moduleName, resourceName string, fields []parser.Field, kitName string) error
GenerateAPI generates a JSON API handler for a resource.
func GenerateApp ¶
func GenerateAuth ¶
func GenerateAuth(projectRoot string, authConfig *AuthConfig) error
func GenerateAuthz ¶
func GenerateAuthz(projectRoot string, cfg *AuthzConfig) error
GenerateAuthz generates the authorization system: role migration, role queries, and patches the schema for sqlc.
func GenerateJob ¶
GenerateJob scaffolds a new job handler and registers it with the worker.
func GenerateQueue ¶
GenerateQueue sets up the background job infrastructure using River. It creates the migration, schema, worker init file, and injects setup into main.go.
func GenerateResource ¶
func GenerateSchema ¶
func GenerateSchema(basePath, moduleName, tableName string, fields []parser.Field, kitName, cssFramework string) error
GenerateSchema generates only database files (migration, schema, queries) without handler or template
func GenerateTask ¶
GenerateTask scaffolds a new scheduled task and registers it.
func GenerateView ¶
func InjectAPIRegistration ¶
InjectAPIRegistration adds api.RegisterRoutes(http.DefaultServeMux, queries) and the api package import to main.go.
func InjectEmbeddedChild ¶
func InjectEmbeddedChild(parentGoPath string, childData ResourceData) error
InjectEmbeddedChild modifies the parent handler (.go file) to integrate an embedded child resource.
It performs the following modifications:
- Add import for the child package
- Add *child.EmbeddedState field to the parent state struct
- Add *child.EmbeddedController field to the parent controller struct
- Initialize the child controller and state in the Handler function
- Add child template files to ParseFiles
- Append forwarding methods (ChildAdd, ChildEdit, ChildUpdate, ChildDelete, ChildCancelEdit)
- Hook into View/Mount to load child data
This function is idempotent — it checks for existing markers before injecting.
func InjectEmbeddedChildTemplate ¶
func InjectEmbeddedChildTemplate(parentTmplPath string, childData ResourceData) error
InjectEmbeddedChildTemplate modifies the parent template (.tmpl file) to include the child section.
It finds the detail page section and inserts {{template "child:section" .Child}} before the closing {{end}}. This function is idempotent.
func InjectRoute ¶
InjectRoute adds an http.Handle route and import to main.go
func ProtectResources ¶
func ProtectResources(projectRoot, _ string, resources []ResourceEntry) error
ProtectResources wraps the specified resource handlers with RequireAuth middleware in main.go.
This function modifies main.go to: 1. Add an auth controller if not present 2. Wrap selected resource handlers with authController.RequireAuth()
Example transformation:
Before: http.Handle("/posts", posts.Handler(queries))
After: http.Handle("/posts", authController.RequireAuth(posts.Handler(queries)))
func ReadDevMode ¶
ReadDevMode reads the dev_mode setting from .lvtrc in the current directory Returns false if .lvtrc doesn't exist or dev_mode is not set
func RegisterResource ¶
RegisterResource adds a resource to the tracking file
func Singularize ¶
Singularize is the exported version of singularize for use by other packages.
func ToCamelCase ¶
ToCamelCase converts snake_case to CamelCase following Go conventions. Common initialisms like ID, URL, HTTP are kept in all caps. Exported for use by CLI commands that need consistent naming.
func UpdateResourceTestsForAuth ¶
UpdateResourceTestsForAuth updates existing resource test files to include authentication. This is called when auth is generated to ensure existing resource tests still work with the newly protected routes.
func ValidateTemplate ¶
ValidateTemplate parses a generated .tmpl file and returns a clear error if the template contains syntax errors. This catches issues at generation time rather than at runtime.
func WrapExistingRoutesWithAuth ¶
WrapExistingRoutesWithAuth finds existing resource routes in main.go and wraps them with RequireAuth middleware. It also adds the authController initialization.
The structName parameter specifies the auth struct name (e.g., "User", "Account", "Admin") which is used to generate the correct controller constructor call.
Before:
http.Handle("/posts", posts.Handler(queries))
After:
// Protected routes - require authentication
baseURL := "http://localhost:8080"
if envURL := os.Getenv("BASE_URL"); envURL != "" {
baseURL = envURL
}
authController := auth.NewUserController(queries, nil, baseURL)
http.Handle("/posts", authController.RequireAuth(posts.Handler(queries)))
func WriteResources ¶
func WriteResources(basePath string, resources []ResourceEntry) error
WriteResources writes the resources list to file
Types ¶
type APIData ¶
type APIData struct {
PackageName string
ModuleName string
ResourceName string
ResourceNameLower string
ResourceNameSingular string
ResourceNamePlural string
TableName string
Fields []FieldData
}
APIData holds template data for API handler generation.
type AuthConfig ¶
type AuthzConfig ¶
type AuthzConfig struct {
ModuleName string // Module path from go.mod
TableName string // Users table name (e.g., "users")
}
AuthzConfig holds configuration for authorization generation.
type ComponentUsage ¶
type ComponentUsage struct {
UseModal bool // delete confirmation modal
UseToast bool // CRUD feedback notifications
UseDropdown bool // select field dropdowns
UseUpload bool // file/image upload support
}
ComponentUsage tracks which UI components are needed by a generated resource.
func ComputeComponentUsage ¶
func ComputeComponentUsage(data ResourceData) ComponentUsage
ComputeComponentUsage determines which components a resource needs based on its field types.
type FieldData ¶
type FieldData struct {
Name string
GoType string
SQLType string
IsReference bool
ReferencedTable string
OnDelete string
IsTextarea bool // true if field should render as textarea
IsSelect bool // true if field should render as <select>
SelectOptions []string // options for select fields
IsFile bool // true if field is a file upload
IsImage bool // true if field is an image upload (subset of file)
parser.FieldMetadata // validation + HTML rendering metadata (embedded)
}
func FieldDataFromFields ¶
FieldDataFromFields converts parsed fields to FieldData for template rendering.
type JobConfig ¶
type JobConfig struct {
ModuleName string
JobName string // snake_case, e.g. "send_email"
JobNameCamel string // CamelCase, e.g. "SendEmail"
}
JobConfig holds configuration for generating a single job handler.
type JobsConfig ¶
type JobsConfig struct {
ModuleName string
}
JobsConfig holds configuration for generating the queue infrastructure.
type ResourceData ¶
type ResourceData struct {
PackageName string
ModuleName string
ResourceName string // Input name, capitalized (e.g., "Users" or "User")
ResourceNameLower string // Input name, lowercase (e.g., "users" or "user")
ResourceNameSingular string // Singular, capitalized (e.g., "User")
ResourceNamePlural string // Plural, capitalized (e.g., "Users")
TableName string // Plural table name (e.g., "users")
Fields []FieldData
Kit *kits.KitInfo // CSS framework kit (new)
CSSFramework string // CSS framework name: "tailwind", "bulma", "pico", "none" (for backward compatibility)
DevMode bool // Use local client library instead of CDN
PaginationMode string // Pagination mode: "infinite", "load-more", "prev-next", "numbers"
PageSize int // Page size for pagination
EditMode string // Edit mode: "modal", "page"
Components ComponentUsage // Which UI components this resource uses
Styles string // Style adapter: "tailwind", "unstyled"
StylesImportPath string // computed import path for style adapter (empty if no components need it)
// Full-text search (set when --searchable is used)
Searchable bool // True when generating with SQLite FTS5 full-text search
// Authorization (set when --with-authz is used)
WithAuthz bool // True when generating with ownership tracking and permission checks
// Embedded child resource fields (set when --parent is used)
ParentResource string // Parent resource name, lowercase plural (e.g., "posts"). Empty = standalone.
ParentPackageName string // Parent package name (e.g., "posts")
ParentResourceSingular string // Parent resource singular capitalized (e.g., "Post")
ParentReferenceField string // FK field referencing parent (e.g., "post_id"), auto-detected
IsEmbedded bool // True when generating as embedded child
}
func (ResourceData) FileFields ¶
func (d ResourceData) FileFields() []FieldData
FileFields returns only file/image fields.
func (ResourceData) NonFileFields ¶
func (d ResourceData) NonFileFields() []FieldData
NonFileFields returns fields excluding file/image fields. Used in handler templates: file data arrives via ctx.GetCompletedUploads, not form JSON.
func (ResourceData) NonReferenceFields ¶
func (d ResourceData) NonReferenceFields() []FieldData
NonReferenceFields returns fields excluding the parent reference field. Used in embedded templates to omit the parent FK from forms.
func (ResourceData) SearchableFields ¶
func (d ResourceData) SearchableFields() []FieldData
SearchableFields returns string fields suitable for FTS indexing (excludes file/image/reference).
type ResourceEntry ¶
type ResourceEntry struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"` // "resource" or "view"
}
ResourceEntry represents a resource or view in the application
func ReadResources ¶
func ReadResources(basePath string) ([]ResourceEntry, error)
ReadResources reads all registered resources
type RouteInfo ¶
type RouteInfo struct {
Path string // e.g., "/users"
PackageName string // e.g., "users"
HandlerCall string // e.g., "users.Handler(queries)"
ImportPath string // e.g., "myapp/app/users"
}
RouteInfo contains information about a route to be injected
type TaskConfig ¶
type TaskConfig struct {
ModuleName string
JobName string
JobNameCamel string
Schedule string // cron expression or shortcut
}
TaskConfig holds configuration for scheduled task generation.
type ViewData ¶
type ViewData struct {
PackageName string
ModuleName string
ViewName string
ViewNameLower string
Kit *kits.KitInfo // CSS framework kit (new)
CSSFramework string // CSS framework: "tailwind", "bulma", "pico", "none" (for backward compatibility)
DevMode bool // Use local client library instead of CDN
}