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 ¶
- Variables
- func Chain(h http.Handler, mw ...func(http.Handler) http.Handler) http.Handler
- func DefaultErrorHandler(w http.ResponseWriter, r *Request, err error)
- func Error(code int, msg string) error
- func Handler(route string, h HandlerFunc, eh ErrorHandler) http.Handler
- func JSON(w http.ResponseWriter, v any) error
- func Logger(next http.Handler) http.Handler
- func ParseInt(s string) (int, bool)
- func ParseInt32(s string) (int32, bool)
- func ParseInt64(s string) (int64, bool)
- func RequestID(next http.Handler) http.Handler
- func Seg(s string) string
- func SegInt(v int64) string
- func SegWild(s string) string
- func URL(path string, opts ...URLOption) string
- type ErrorHandler
- type HTTPError
- type HandlerFunc
- type Request
- type Route
- type RouteParam
- type URLOption
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 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 ¶
Logger writes one slog line per request: method, path, status, bytes elided, duration.
func ParseInt32 ¶
ParseInt32 parses a decimal int32 path parameter.
func ParseInt64 ¶
ParseInt64 parses a decimal int64 path parameter.
func RequestID ¶
RequestID ensures an X-Request-ID header on request and response, generating a random one when the client sent none.
func Seg ¶
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.
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 ¶
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 ¶
Request wraps *http.Request with route identity. It is passed to controller methods; everything else about the request is the embedded stdlib value.
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 ¶
RouteParam describes one captured parameter of a table row.
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. |