volt

package module
v0.0.0-...-fcb4ad6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package volt is the runtime for code generated by the volt CLI: the handler shim with its error spine, the reverse-URL building blocks, the route-table types, and a minimal middleware set.

The package is deliberately small and stdlib-only (nao's rt contract, D03, applied to the router): generated code imports the standard library and this package, nothing else. Middleware everywhere uses the ecosystem contract func(http.Handler) http.Handler (R8); controller methods carry the one non-stdlib shape in the system, func(http.ResponseWriter, *volt.Request, params...) error (R3).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound   = Error(http.StatusNotFound, "not found")
	ErrBadRequest = Error(http.StatusBadRequest, "bad request")
	ErrForbidden  = Error(http.StatusForbidden, "forbidden")
)

Sentinels for the common cases. ErrNotFound is also what generated shims return when a typed path parameter fails to parse (R6: a parse failure is that route's 404, never a fallthrough).

Functions

func Chain

func Chain(h http.Handler, mw ...func(http.Handler) http.Handler) http.Handler

Chain composes middleware around h: the first element is outermost, matching pipeline declaration order.

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, r *Request, err error)

DefaultErrorHandler maps HTTPError to its status and message and everything else to a generic 500, logging the underlying error. On a committed response it only logs.

func Error

func Error(code int, msg string) error

Error builds an HTTPError with the given status code and message.

func Handler

func Handler(route string, h HandlerFunc, eh ErrorHandler) http.Handler

Handler adapts a HandlerFunc plus an ErrorHandler into a std http.Handler; generated registrations wrap every route through it.

func JSON

func JSON(w http.ResponseWriter, v any) error

JSON writes v as a JSON response with the right Content-Type. Copy-paste and customize freely — like nao's rt.JSON, it is a convenience, not a framework.

func Logger

func Logger(next http.Handler) http.Handler

Logger writes one slog line per request: method, path, status, bytes elided, duration.

func ParseInt

func ParseInt(s string) (int, bool)

ParseInt parses a decimal int path parameter.

func ParseInt32

func ParseInt32(s string) (int32, bool)

ParseInt32 parses a decimal int32 path parameter.

func ParseInt64

func ParseInt64(s string) (int64, bool)

ParseInt64 parses a decimal int64 path parameter.

func RequestID

func RequestID(next http.Handler) http.Handler

RequestID ensures an X-Request-ID header on request and response, generating a random one when the client sent none.

func Seg

func Seg(s string) string

Seg escapes one string path parameter. "." and ".." escape to their %2E forms: PathEscape leaves dots alone, but as whole segments they would change the path shape under cleaning (and ServeMux redirects unclean paths), so a built URL must never contain them literally.

func SegInt

func SegInt(v int64) string

SegInt renders an integer path parameter.

func SegWild

func SegWild(s string) string

SegWild escapes a rest-of-path value, preserving its '/' separators. Each element gets Seg's treatment, dot segments included.

func URL

func URL(path string, opts ...URLOption) string

URL finishes a generated path: it appends the encoded query built from opts. The path itself is assembled by the generated helper with the Seg/SegInt/SegWild builders below.

Types

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, *Request, error)

ErrorHandler consumes a handler error. When Request.Committed() is true it must not write status or body.

type HTTPError

type HTTPError interface {
	error
	StatusCode() int
}

HTTPError is the error-to-status contract: a handler error carrying its own response code. DefaultErrorHandler and user error handlers map it via errors.As-compatible assertion.

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *Request) error

HandlerFunc is the controller-side shape after parameter binding.

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Request wraps *http.Request with route identity. It is passed to controller methods; everything else about the request is the embedded stdlib value.

func (*Request) Committed

func (r *Request) Committed() bool

Committed reports whether the response header has been written. An error returned after commit reaches the error handler in log-only mode (§4.1 of the router spec).

func (*Request) Route

func (r *Request) Route() string

Route returns the matched route's ServeMux pattern (metrics-safe cardinality, ROUTE-19 parity).

type Route

type Route struct {
	Method     string // "" for the any-verb
	Pattern    string // ServeMux pattern
	Spelled    string // DSL spelling
	Controller string
	Action     string
	Helper     string // reverse-URL function name, "" when none
	Params     []RouteParam
}

Route is one row of the generated route table (volt_routes.go).

type RouteParam

type RouteParam struct {
	Name string
	Type string // int, int32, int64, string
	Wild bool
}

RouteParam describes one captured parameter of a table row.

type URLOption

type URLOption interface {
	// contains filtered or unexported methods
}

URLOption augments a generated reverse-URL helper, today with query parameters: paths.User(42, volt.Query("tab", "posts")).

func Query

func Query(k, v string) URLOption

Query adds one query parameter to a reverse URL.

Directories

Path Synopsis
cmd
volt command
Command volt is the one binary of the Volt language: the CLI front end over the lang package plus the router generator, built on urfave/cli in the style of nao (D41):
Command volt is the one binary of the Volt language: the CLI front end over the lang package plus the router generator, built on urfave/cli in the style of nao (D41):
gen
router
Package router generates the Volt router files for one checked package (spec §V, router spec §4): volt_handlers.go (controller interfaces + the New constructor), volt_router.go (ServeMux registrations with typed shims and statically composed pipelines), volt_paths.go (typed reverse-URL helpers) and volt_routes.go (the introspectable route table).
Package router generates the Volt router files for one checked package (spec §V, router spec §4): volt_handlers.go (controller interfaces + the New constructor), volt_router.go (ServeMux registrations with typed shims and statically composed pipelines), volt_paths.go (typed reverse-URL helpers) and volt_routes.go (the introspectable route table).
itest
fadn/app
Package app is the itest fixture: the hand-written side of the generated router — middleware and the error handler the routes.volt file references by name.
Package app is the itest fixture: the hand-written side of the generated router — middleware and the error handler the routes.volt file references by name.
Package lang implements the project-level semantics of the Volt language (SPEC.md §V): package and import resolution, pipeline and scope checking, route expansion and conflict detection.
Package lang implements the project-level semantics of the Volt language (SPEC.md §V): package and import resolution, pipeline and scope checking, route expansion and conflict detection.
nao
cmd/nao command
Command nao ("not an ORM") is the one binary of the project (D41): the CLI front end over the edbml/ language packages plus the generators, built on urfave/cli:
Command nao ("not an ORM") is the one binary of the project (D41): the CLI front end over the edbml/ language packages plus the generators, built on urfave/cli:
edbml/ast
Package ast declares the types used to represent DBML syntax trees, mirroring the role of go/ast.
Package ast declares the types used to represent DBML syntax trees, mirroring the role of go/ast.
edbml/check
Package check implements semantic analysis of a parsed DBML file — the role go/types plays for Go.
Package check implements semantic analysis of a parsed DBML file — the role go/types plays for Go.
edbml/diag
Package diag defines the diagnostic type shared by the parser, the semantic checker and vet analyzers, so each stage stays decoupled while producing a uniform stream of findings.
Package diag defines the diagnostic type shared by the parser, the semantic checker and vet analyzers, so each stage stays decoupled while producing a uniform stream of findings.
edbml/lsp
Package lsp implements the EDBML language server.
Package lsp implements the EDBML language server.
edbml/parser
Package parser turns DBML source into an ast.File, mirroring go/parser.
Package parser turns DBML source into an ast.File, mirroring go/parser.
edbml/scanner
Package scanner tokenizes DBML source (spec §3), playing the role of go/scanner in the Go toolchain.
Package scanner tokenizes DBML source (spec §3), playing the role of go/scanner in the Go toolchain.
edbml/token
Package token defines the lexical tokens of DBML and source positions, mirroring the role of go/token in the Go toolchain.
Package token defines the lexical tokens of DBML and source positions, mirroring the role of go/token in the Go toolchain.
edbml/vet
Dynamic-layer name analyzer — feature DYN-7: the dynamic query layer (decisions D28-D30) mints package-scope Go names by concatenation (UserEmail, UserLimit), so distinct DBML declarations can demand one Go name.
Dynamic-layer name analyzer — feature DYN-7: the dynamic query layer (decisions D28-D30) mints package-scope Go names by concatenation (UserEmail, UserLimit), so distinct DBML declarations can demand one Go name.
gen/golang
Dynamic-query generation (nao_dyn.go): the v2 surface of Not an ORM (decisions D28-D34).
Dynamic-query generation (nao_dyn.go): the v2 surface of Not an ORM (decisions D28-D34).
gen/sqlite
Package sqlite generates SQLite DDL (nao_schema.sql) from a checked DBML file: CREATE TABLE per table, CREATE INDEX per non-pk index, and INSERT statements from records.
Package sqlite generates SQLite DDL (nao_schema.sql) from a checked DBML file: CREATE TABLE per table, CREATE INDEX per non-pk index, and INSERT statements from records.
inflect
Package inflect derives the singular model name from a plural table name (decision D10).
Package inflect derives the singular model name from a plural table name (decision D10).
itest
Package itest contains data models generated from schema.dbml.
Package itest contains data models generated from schema.dbml.
rt
The dynamic query layer (decisions D28-D34): predicates, orderings, limits and assignments as inert data — plain values forming a small expression tree, never closures and never a mutable builder.
The dynamic query layer (decisions D28-D34): predicates, orderings, limits and assignments as inert data — plain values forming a small expression tree, never closures and never a mutable builder.

Jump to

Keyboard shortcuts

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