Documentation
¶
Overview ¶
Package validation provides a unified engine for validating generated LiveTemplate applications. It aggregates multiple checks (go.mod structure, template syntax, SQL migrations, compilation) into a single pass and reports issues using the shared validator.ValidationResult type.
Index ¶
- func Validate(ctx context.Context, appPath string) *validator.ValidationResult
- func ValidateFull(ctx context.Context, appPath string) *validator.ValidationResult
- func ValidatePostGen(ctx context.Context, appPath string) *validator.ValidationResult
- type Check
- type CompilationCheck
- type Engine
- type GoModCheck
- type MigrationCheck
- type Option
- type RuntimeCheck
- type TemplateCheck
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Validate ¶
func Validate(ctx context.Context, appPath string) *validator.ValidationResult
Validate runs all default checks including compilation (go build ./...). This may be slow if dependencies are not cached. Use NewEngine with selective checks for latency-sensitive call sites (e.g. file watchers).
func ValidateFull ¶
func ValidateFull(ctx context.Context, appPath string) *validator.ValidationResult
ValidateFull runs all checks including the runtime startup check. This is the most thorough validation and is the most expensive.
func ValidatePostGen ¶
func ValidatePostGen(ctx context.Context, appPath string) *validator.ValidationResult
ValidatePostGen runs structural checks (no compilation) after code generation. Use this right after lvt gen commands where the app may not yet compile.
Types ¶
type Check ¶
type Check interface {
// Name returns a human-readable name for the check (e.g. "go.mod").
Name() string
// Run executes the check and returns issues found.
Run(ctx context.Context, appPath string) *validator.ValidationResult
}
Check is a single validation check that can be run against an app directory.
type CompilationCheck ¶
type CompilationCheck struct {
// RunGoModTidy runs go mod tidy before building. Off by default because
// it mutates go.mod/go.sum in the target directory.
RunGoModTidy bool
// RunSqlc runs sqlc generate before building (if sqlc.yaml exists and
// queries.sql has content). Off by default because it requires a locally
// installed sqlc binary.
RunSqlc bool
}
CompilationCheck runs sqlc generate (optional), go mod tidy (opt-in), and go build on an app directory. By default only go build runs; set RunGoModTidy or RunSqlc to true to enable those steps.
func (*CompilationCheck) Name ¶
func (c *CompilationCheck) Name() string
func (*CompilationCheck) Run ¶
func (c *CompilationCheck) Run(ctx context.Context, appPath string) *validator.ValidationResult
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates multiple validation checks.
func DefaultEngine ¶
func DefaultEngine() *Engine
DefaultEngine returns an engine pre-loaded with all built-in checks.
func FullEngine ¶
func FullEngine() *Engine
FullEngine returns an engine with all default checks plus RuntimeCheck. RuntimeCheck is expensive (builds binary, starts subprocess, probes HTTP) so it is not included in DefaultEngine.
func PostGenEngine ¶
func PostGenEngine() *Engine
PostGenEngine returns an engine suited for post-generation validation. It checks structural aspects (go.mod, templates, migrations) but skips compilation because the app may not compile until sqlc generate is run.
type GoModCheck ¶
type GoModCheck struct{}
GoModCheck validates the go.mod file in an app directory.
func (*GoModCheck) Name ¶
func (c *GoModCheck) Name() string
func (*GoModCheck) Run ¶
func (c *GoModCheck) Run(_ context.Context, appPath string) *validator.ValidationResult
type MigrationCheck ¶
type MigrationCheck struct{}
MigrationCheck validates SQL migration files against an in-memory SQLite DB. Because apps may target PostgreSQL, SQL execution errors are reported as warnings (they may be false positives for non-SQLite dialects). Structural issues (missing files, missing goose directives) are always reported.
func (*MigrationCheck) Name ¶
func (c *MigrationCheck) Name() string
func (*MigrationCheck) Run ¶
func (c *MigrationCheck) Run(ctx context.Context, appPath string) *validator.ValidationResult
type Option ¶
type Option func(*Engine)
Option configures an Engine.
func WithTimeout ¶
WithTimeout sets the maximum duration for all checks combined.
type RuntimeCheck ¶
type RuntimeCheck struct {
// StartupTimeout is how long to wait for the app to start listening.
// Defaults to 15s if zero.
StartupTimeout time.Duration
// Port to run the app on. 0 means auto-allocate a free port.
Port int
// Routes to probe after the app starts. Defaults to ["/"] if empty.
Routes []string
}
RuntimeCheck builds the app binary, starts it, and probes HTTP routes. It implements the Check interface and is opt-in (not in DefaultEngine) because it is expensive: it compiles a binary, starts a subprocess, and makes HTTP requests.
func (*RuntimeCheck) Name ¶
func (c *RuntimeCheck) Name() string
func (*RuntimeCheck) Run ¶
func (c *RuntimeCheck) Run(ctx context.Context, appPath string) *validator.ValidationResult
type TemplateCheck ¶
type TemplateCheck struct{}
TemplateCheck validates all .tmpl files in an app directory using html/template (matching the existing generator/validate.go convention).
func (*TemplateCheck) Name ¶
func (c *TemplateCheck) Name() string
func (*TemplateCheck) Run ¶
func (c *TemplateCheck) Run(ctx context.Context, appPath string) *validator.ValidationResult