Documentation
¶
Overview ¶
Package avero is the name that an application writes.
It holds aliases and thin wrappers for the subsystem packages. It holds no logic and no state, so it is not a facade: it hides nothing and it adds no behaviour. Read the subsystem package for the contract of a name.
config the configuration loader and the report, S1 host the lifecycle, the readiness gate and the boot checks, S2 router the routes, the request context and the middleware, S4 module the module contract and the module inspection, S6 view the helpers of a server rendered page, S10 assets the asset pipeline and the manifest, S11
The hypermedia adapters, ds and htmx, are optional imports. This package holds no alias for them, so an application that needs neither carries neither. See the SDD, S12.
telemetry the traces, the metrics and the logger, S3
An application can import a subsystem directly. The two forms are the same types.
Index ¶
- Constants
- Variables
- func AppName() string
- func AppVersion() string
- func AssetHandler(fsys fs.FS, m *Manifest) http.Handler
- func Attr(key string, value any) attribute.KeyValue
- func Delete[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption)
- func Exit(w io.Writer, err error) int
- func FieldError(ctx context.Context, field string) string
- func FileAccepted(file *multipart.FileHeader, types ...string) bool
- func FileType(file *multipart.FileHeader) string
- func Get[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption)
- func HasError(ctx context.Context, field string) bool
- func Inspect[T any](args []string, out, errOut io.Writer, r *Router, set *ModuleSet, ...) int
- func Inspecting(args []string) bool
- func Load[T any](ctx context.Context) (*T, error)
- func MustTx(ctx context.Context) *drel.Tx
- func Old(ctx context.Context, field string) string
- func OldFrom(ctx context.Context) any
- func Patch[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption)
- func Post[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption)
- func Put[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption)
- func Repo[T any](ctx context.Context, meta drel.ModelMeta[T]) (*drel.TxRepository[T], error)
- func Save(ctx context.Context) error
- func Serve[C Configurer](s Service[C]) int
- func Session(ctx context.Context) *store.Session
- func Tx(ctx context.Context) (*drel.Tx, bool)
- func UnpackMigrations(fsys fs.FS, root string) (string, func(), error)
- func User(ctx context.Context) *store.User
- func WithAPI(api API) router.Option
- func WithForm(page func(c *Ctx, f *Fields) ViewComponent) router.Option
- func WithResponder(fn Responder) router.Option
- type API
- type App
- type AssetEntry
- type BaseConfig
- type Binder
- type Check
- func BrokerCheck(address string) Check
- func DatabaseCheck(dsn string) Check
- func DatabaseCheckOn(e *drel.Engine) Check
- func MigrationCheck(dsn, dir string) Check
- func MigrationCheckFS(dsn string, sets ...fs.FS) Check
- func MigrationCheckOn(e *drel.Engine, dir string) Check
- func MigrationCheckOnFS(e *drel.Engine, sets ...fs.FS) Check
- func SecretCheck(secret Secret) Check
- type Component
- type Configurer
- type Contact
- type Contribution
- type Ctx
- type DescribeModule
- type Description
- type EventDesc
- type ExternalDocs
- type Field
- type FieldDesc
- type Fields
- type HTTPModule
- type Handler
- type InboxHandler
- type InboxModule
- type Job
- type License
- type Loader
- type Manifest
- type Middleware
- func AccessLog(l *slog.Logger) Middleware
- func Adapt(name string, mw func(http.Handler) http.Handler) Middleware
- func CSRF(secret Secret, opts ...router.CookieOption) Middleware
- func Flash(secret Secret, opts ...router.CookieOption) Middleware
- func MaxBytes(n int64) Middleware
- func Recover(l *slog.Logger) Middleware
- func RequestID() Middleware
- func Transaction(e *drel.Engine) Middleware
- type MigrationModule
- type Migrator
- type ModelDesc
- type ModelModule
- type Module
- type ModuleReport
- type ModuleSet
- type MountOption
- type NoBody
- type OTelConfig
- type OpOption
- func AnswerHeader(code int, name, description string) OpOption
- func Answers[T any](code int, description string) OpOption
- func AnswersNothing(code int, description string) OpOption
- func Deprecated() OpOption
- func Describe(text string) OpOption
- func Public() OpOption
- func Secured(schemes ...string) OpOption
- func Summary(text string) OpOption
- func Tags(names ...string) OpOption
- type Option
- func WithChecks(cs ...Check) Option
- func WithComponents(cs ...Component) Option
- func WithHandler(h http.Handler) Option
- func WithListener(l net.Listener) Option
- func WithLogger(l *slog.Logger) Option
- func WithMigrator(m Migrator) Option
- func WithSignals(sig ...os.Signal) Option
- func WithoutSignals() Option
- type Problem
- type Projection
- type ProjectorModule
- type Ready
- type Report
- type Responder
- type Response
- func Empty(code int) Response
- func HTML(code int, body string) Response
- func JSON(code int, body any) Response
- func NoContent() Response
- func Redirect(code int, to string) Response
- func Status(code int) Response
- func Text(code int, body string) Response
- func View(c ViewComponent) Response
- func ViewStatus(code int, c ViewComponent) Response
- type Route
- type RouteDesc
- type RouteReport
- type Router
- type ScheduleModule
- type Scheduler
- type SchemaReport
- type Secret
- type SecurityScheme
- type Server
- type Service
- type Source
- type Stack
- type Tag
- type Telemetry
- type TelemetryOption
- type Toast
- type Validator
- type ViewComponent
- type ViewFunc
- type Wiring
Constants ¶
const ( SourceEnv = config.SourceEnv SourceDefault = config.SourceDefault SourceAbsent = config.SourceAbsent )
The sources that a report names.
const ( ToastInfo = router.ToastInfo ToastSuccess = router.ToastSuccess ToastWarning = router.ToastWarning ToastError = router.ToastError // StatusCSRF is the status of a CSRF fault. StatusCSRF = router.StatusCSRF )
The toast levels and the CSRF status.
const InspectPrefix = "avero:"
InspectPrefix marks a command that the avero binary sends to the application. The CLI runs `go run . avero:routes`, because the routes and the modules of an application live in its own code. See the SDD, S14.
const MaxMultipartMemory = router.MaxMultipartMemory
MaxMultipartMemory is the number of bytes of a multipart request that stand in memory. See router.MaxMultipartMemory.
const MigrateCommand = "migrate"
MigrateCommand is the inspection command that applies the migrations of the modules of an application, or reports the migrations that are pending.
The migrations of a module stand in the binary of the application, so the application applies them and the CLI asks for it. `avero migrate up` runs `go run . avero:migrate up`.
const NoModuleMigrations = 3
NoModuleMigrations is the exit code of `avero:migrate` for an application whose modules state no migration.
The CLI reads it and applies the files of the migrations directory that avero.json names, so an application that holds SQL of its own keeps the reader of Avero.
const ProblemContentType = router.ProblemContentType
ProblemContentType is the media type of a problem document.
const Redacted = config.Redacted
Redacted replaces the value of a secret field wherever Avero prints it.
Variables ¶
var ( // ErrNotFound states that the path names no thing. 404. ErrNotFound = router.ErrNotFound ErrUnauthorized = router.ErrUnauthorized // ErrForbidden states that the identity may not do this. 403. ErrForbidden = router.ErrForbidden // ErrConflict states that the state of the thing refuses the change. 409. ErrConflict = router.ErrConflict // ErrBadRequest states that the request does not read. 400. ErrBadRequest = router.ErrBadRequest // ErrInternal states a fault of the service. 500. ErrInternal = router.ErrInternal )
The problems that a service answers most. Compare with errors.Is.
Functions ¶
func AppName ¶ added in v0.3.0
func AppName() string
AppName returns the name of the application, which the description of the API carries.
The binary reads its own module path, so a person needs to state the name in no second place.
func AppVersion ¶ added in v0.3.0
func AppVersion() string
AppVersion returns the version of the application, which the description of the API carries. A build from the source names 0.0.0.
func AssetHandler ¶
AssetHandler serves the built assets of a manifest. See assets.Handler.
r.Mount("/assets/", avero.AssetHandler(dist, m))
func Attr ¶
Attr builds a span attribute. A Secret reads as ******** and never reaches an exporter. See telemetry.Attr.
func Delete ¶ added in v0.3.0
func Delete[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption, )
Delete registers a typed DELETE route.
func Exit ¶
Exit writes err to w and returns the process exit code. It returns 0 for a nil error and 1 for any fault. It prints a configuration fault with the config format and every other fault with the host format. The caller owns the call to os.Exit.
func FieldError ¶
FieldError returns the validation message of this field.
The SDD names this helper Error. The root package already holds the Error name in the toast API of Ctx, and a package level Error reads as a fault type in Go. The view package holds the name that the SDD states, and a component calls view.Error.
func FileAccepted ¶ added in v0.6.0
func FileAccepted(file *multipart.FileHeader, types ...string) bool
FileAccepted reports a file whose declared media type stands in the list. See router.FileAccepted.
func FileType ¶ added in v0.6.0
func FileType(file *multipart.FileHeader) string
FileType returns the media type that the client declared for one file. See router.FileType.
func Get ¶ added in v0.3.0
func Get[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption, )
Get registers a typed GET route.
func Inspect ¶
func Inspect[T any](args []string, out, errOut io.Writer, r *Router, set *ModuleSet, checks ...Check) int
Inspect answers one inspection command and returns the exit code.
The type parameter is the configuration of the application, so avero:doctor reports every variable that the application reads. The checks are the boot checks, so the doctor answers the question that DX-8 asks before the process starts.
func Inspecting ¶
Inspecting reports an inspection command. The application calls it before it loads the configuration and before it opens the database, so an inspection needs neither.
func main() {
r, modules := wire(nil)
if avero.Inspecting(os.Args[1:]) {
os.Exit(avero.Inspect[Config](os.Args[1:], os.Stdout, os.Stderr, r, modules))
}
os.Exit(run())
}
func MustTx ¶ added in v0.5.0
MustTx returns the transaction and panics when none is present. See db.MustTx.
func Patch ¶ added in v0.3.0
func Patch[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption, )
Patch registers a typed PATCH route.
func Post ¶ added in v0.3.0
func Post[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption, )
Post registers a typed POST route. The success answer is 201.
func Put ¶ added in v0.3.0
func Put[T any, P router.Input[T], V any](r *Router, pattern string, fn func(c *Ctx, in T) (V, error), opts ...OpOption, )
Put registers a typed PUT route.
func Repo ¶ added in v0.4.0
Repo returns the repository of the transaction of the request. See db.Repo.
The transaction middleware opens the transaction, so a handler always holds one. A job that reads outside a request opens its own with engine.WithTx.
repo, err := avero.Repo(ctx, model.PostMeta)
func Save ¶ added in v0.4.0
Save writes the staged changes inside the transaction of the request. See db.Save.
The transaction still commits at the end of the request. The flush only makes a later read of the same request see the write.
func Serve ¶ added in v0.4.0
func Serve[C Configurer](s Service[C]) int
Serve runs one Avero application and returns the exit code of the process.
It runs the sequence of section 5.3 of the SDD. It answers an inspection command, loads the configuration, and opens the database. It builds the router and registers the boot checks and the migrator. It then runs the application until a signal or the end of the context.
An application with an unusual start calls Load, New and Run itself. Serve adds no behaviour that those three do not hold.
func main() {
os.Exit(avero.Serve(avero.Service[Config]{
Args: os.Args[1:],
Wire: wire,
DSN: func(c Config) string { return c.DatabaseURL },
}))
}
func Session ¶ added in v0.5.0
Session returns the auth-all session of the request, or nil. See auth.Session.
func Tx ¶ added in v0.5.0
Tx returns the transaction that Transaction opened, and reports whether one surrounds the request. See db.Tx.
func UnpackMigrations ¶ added in v0.2.0
UnpackMigrations writes the migrations of an embedded file system into a temporary directory and returns it with the function that removes it.
An application that embeds its migrations therefore applies them from its own binary, and one artifact holds the server, the front end and the schema.
//go:embed all:migrations var migrations embed.FS dir, clean, err := avero.UnpackMigrations(migrations, "migrations") defer clean()
func WithForm ¶
func WithForm(page func(c *Ctx, f *Fields) ViewComponent) router.Option
WithForm renders the form again with 422 when validation fails. Pass it to NewRouter. See view.WithForm.
func WithResponder ¶ added in v0.5.0
WithResponder sets how a typed handler turns its value into a Response. The default writes JSON. See router.WithResponder.
r := avero.NewRouter(avero.WithResponder(func(c *avero.Ctx, code int, v any) avero.Response {
if component, ok := v.(avero.ViewComponent); ok {
return avero.View(component)
}
return avero.JSON(code, v)
}))
Types ¶
type API ¶ added in v0.3.0
API states the facts of the whole description of an API: the name, the prose, the addresses, the schemes of the identity and the groups. See router.API.
type BaseConfig ¶
type BaseConfig = config.BaseConfig
BaseConfig holds the variables that every Avero application reads.
type Check ¶
Check is one boot check.
func BrokerCheck ¶
BrokerCheck proves that the broker accepts a connection. It opens a TCP connection to the host of the address, because the broker library belongs to the application.
func DatabaseCheck ¶
DatabaseCheck proves that the database answers. It opens its own connection, so `avero doctor` runs it with no application. An application that already holds an engine passes it to DatabaseCheckOn.
func DatabaseCheckOn ¶
DatabaseCheckOn proves the database with an engine that the application already opened.
func MigrationCheck ¶
MigrationCheck proves that the database holds every migration of the directory. It opens its own connection, so `avero doctor` runs it with no application. An application that already holds an engine passes it to MigrationCheckOn, which opens nothing.
Register it with WithChecks, so a pending migration stops the process before it serves. See DX-8.
func MigrationCheckFS ¶ added in v0.2.0
MigrationCheckFS proves the embedded migration sets against a database that the check opens itself. `avero doctor` holds no engine, so it uses this one.
func MigrationCheckOn ¶
MigrationCheckOn proves the migrations with an engine that the application already opened.
func MigrationCheckOnFS ¶ added in v0.2.0
MigrationCheckOnFS proves the migrations of the embedded sets of the feature slices. Each slice embeds its own, and drel merges them in version order.
func SecretCheck ¶
SecretCheck returns a boot check that proves AVERO_SECRET is long enough to sign a cookie. Register it with WithChecks, so that a weak secret stops the process with a repair sentence instead of a panic inside the router wiring. See DX-8.
app := avero.New(cfg.BaseConfig,
avero.WithChecks(avero.SecretCheck(cfg.Secret)),
avero.WithHandler(handler))
type Configurer ¶ added in v0.4.0
type Configurer interface {
Base() BaseConfig
}
Configurer gives Serve the base configuration of an application.
BaseConfig carries the method, so a configuration that embeds it satisfies the constraint and writes no code.
type Contribution ¶
type Contribution = module.Contribution
Contribution is one row of the contribution table.
type DescribeModule ¶
type DescribeModule = module.DescribeModule
DescribeModule states the description that an agent reads.
type Description ¶
type Description = module.Description
Description states what one module contributes. See AN-3.
type ExternalDocs ¶ added in v0.3.0
type ExternalDocs = router.ExternalDocs
ExternalDocs names a document that stands outside this one.
type Fields ¶
Fields holds one message for each field that failed validation.
func FieldsFrom ¶
FieldsFrom returns the validation result of a failed request. S10 renders the form again from it.
type Handler ¶
Handler is one typed handler.
func In ¶
func In[T any, P interface { *T Binder Validator }](fn func(c *Ctx, in T) (Response, error), ) Handler
In adapts a typed handler to the router. The constraint requires the Bind and Validate methods that `avero generate` writes, so a missing or stale generated file is a compile fault at the route. See router.In.
r.Post("/things", avero.In(m.Create))
type Manifest ¶
Manifest maps the name of an asset to the built file.
func LoadManifest ¶
LoadManifest reads the asset manifest from an embedded file system. See assets.LoadManifest.
//go:embed all:assets/dist var dist embed.FS m, err := avero.LoadManifest(dist, "assets/dist/manifest.json")
func MountAssets ¶ added in v0.4.0
MountAssets reads the manifest of the built assets and serves them at /assets/.
root is the directory of the built output inside dist, such as "assets/dist". The manifest stands beside the files, so the caller states one path and not two. Mount strips the prefix, so the handler reads the path of the asset.
manifest, err := avero.MountAssets(r, dist, "assets/dist")
type Middleware ¶
type Middleware = router.Middleware
Middleware wraps a handler and carries a name.
func AccessLog ¶
func AccessLog(l *slog.Logger) Middleware
AccessLog writes one line for each request.
func CSRF ¶
func CSRF(secret Secret, opts ...router.CookieOption) Middleware
CSRF protects an unsafe method with a signed double-submit token. Pass cfg.Secret, which BaseConfig reads from AVERO_SECRET.
func Flash ¶
func Flash(secret Secret, opts ...router.CookieOption) Middleware
Flash carries a Toast from one request to the next. Pass cfg.Secret, which BaseConfig reads from AVERO_SECRET.
func MaxBytes ¶ added in v0.6.0
func MaxBytes(n int64) Middleware
MaxBytes refuses a request body that is larger than n bytes. An application that reads an upload states it, so a body cannot fill the disk of the server before a rule of a field reads the size of the file. See router.MaxBytes.
r.Use(avero.MaxBytes(10 << 20))
func Transaction ¶
func Transaction(e *drel.Engine) Middleware
Transaction opens a drel transaction and decides the commit from the response. See db.Transaction.
It stands in the Tx field of Stack. A nil engine returns the zero middleware, which Stack leaves out.
type MigrationModule ¶
type MigrationModule = module.MigrationModule
MigrationModule contributes migration files.
type ModelModule ¶ added in v0.4.0
type ModelModule = module.ModelModule
ModelModule states the persistent models of a module. `avero generate` writes the method.
type ModuleReport ¶
ModuleReport lists the contribution of every module.
type MountOption ¶ added in v0.5.0
type MountOption = router.MountOption
MountOption states one more fact of a mount.
func KeepPrefix ¶ added in v0.5.0
func KeepPrefix() MountOption
KeepPrefix passes the whole path to a mounted handler. See router.KeepPrefix.
r.Mount("/api/auth", auth.Handler(), avero.KeepPrefix())
type NoBody ¶ added in v0.3.0
NoBody is the answer of a handler that carries none. The router writes 204. See router.NoBody.
type OTelConfig ¶
type OTelConfig = config.OTelConfig
OTelConfig holds the standard OTEL_* variables.
type OpOption ¶ added in v0.3.0
OpOption states one more fact of an operation, such as a tag or another answer.
func AnswerHeader ¶ added in v0.3.0
AnswerHeader states a header that one answer carries, such as Location on a 201.
func Answers ¶ added in v0.3.0
Answers states one more status that the operation writes.
avero.Post(r, "/posts", m.Create, avero.Answers[avero.Problem](409, "the title is taken"))
func AnswersNothing ¶ added in v0.3.0
AnswersNothing states one more status that the operation writes with no body.
func Deprecated ¶ added in v0.3.0
func Deprecated() OpOption
Deprecated marks an operation that a caller must leave.
func Describe ¶ added in v0.3.0
Describe states the operation at length, where a summary is one line.
type Option ¶
Option configures an application.
func WithChecks ¶
WithChecks registers boot checks. See host.WithChecks.
func WithComponents ¶
WithComponents registers components. See host.WithComponents.
func WithHandler ¶
WithHandler mounts the application handler. See host.WithHandler.
func WithListener ¶
WithListener supplies the listener. See host.WithListener.
func WithLogger ¶
WithLogger supplies the logger. See host.WithLogger.
func WithMigrator ¶
WithMigrator supplies the migrator. See host.WithMigrator.
func WithSignals ¶
WithSignals sets the signals that close the application. See host.WithSignals.
func WithoutSignals ¶
func WithoutSignals() Option
WithoutSignals installs no signal handler. See host.WithoutSignals.
type Problem ¶ added in v0.3.0
Problem is one error of an API, in the shape that RFC 9457 states. See router.Problem.
func BadRequest ¶ added in v0.3.0
BadRequest returns the problem of a request that does not read.
func NewProblem ¶ added in v0.3.0
NewProblem returns a problem with the standard title of the status. See router.NewProblem.
func NotFound ¶ added in v0.3.0
NotFound returns the problem of a thing that the table does not hold.
return nil, avero.NotFound("post", in.ID)
func ProblemOf ¶ added in v0.3.0
ProblemOf returns the problem that an error carries. See router.ProblemOf.
func Unauthorized ¶ added in v0.3.0
Unauthorized returns the problem of a request with no identity.
type ProjectorModule ¶
type ProjectorModule = module.ProjectorModule
ProjectorModule contributes projections.
type Responder ¶ added in v0.5.0
Responder turns the value that a typed handler returned into a Response. See router.Responder.
type Response ¶
Response is the result of a handler.
func View ¶
func View(c ViewComponent) Response
View renders a component with 200 and the HTML content type.
return avero.View(pages.Index(posts)), nil
func ViewStatus ¶
func ViewStatus(code int, c ViewComponent) Response
ViewStatus renders a component with this status. See view.ViewStatus.
type ScheduleModule ¶
type ScheduleModule = module.ScheduleModule
ScheduleModule contributes scheduled jobs.
type SchemaReport ¶
type SchemaReport = module.SchemaReport
SchemaReport lists the models of every module. `avero schema` prints it.
func Schema ¶
func Schema(set *ModuleSet) *SchemaReport
Schema returns the models that the modules describe.
type SecurityScheme ¶ added in v0.3.0
type SecurityScheme = router.SecurityScheme
SecurityScheme states how a caller proves its identity.
func APIKeyAuth ¶ added in v0.3.0
func APIKeyAuth(header, description string) SecurityScheme
APIKeyAuth returns the scheme of a key that a header carries.
func BasicAuth ¶ added in v0.3.0
func BasicAuth(description string) SecurityScheme
BasicAuth returns the scheme of a name and a password.
func BearerAuth ¶ added in v0.3.0
func BearerAuth(description string) SecurityScheme
BearerAuth returns the scheme of a bearer token.
type Service ¶ added in v0.4.0
type Service[C Configurer] struct { // Args holds the command line without the name of the program. Pass // os.Args[1:]. Args []string // Wire builds the wiring of the application. An inspection command // passes a nil engine, and every command but `avero doctor` passes a // zero configuration. Wire func(engine *drel.Engine, cfg C) (*Wiring, error) // DSN reads the database address from the configuration. A nil value // starts an application with no database. DSN func(cfg C) string // Options pass to New after the options that Serve builds, so an // application can add a component or a check of its own. Options []Option // Ctx is the context of the run. A nil value uses context.Background. Ctx context.Context // Out and Err receive the output. A nil value uses os.Stdout and // os.Stderr. Out, Err io.Writer }
Service states the parts of one application that Serve needs.
The zero value of every optional field states a sensible default, so a simple application fills three fields. See the SDD, 5.3, for the sequence that Serve runs.
type Stack ¶ added in v0.4.0
Stack builds the whole middleware chain in the order that the SDD states. An application states the parts that it runs, and Stack orders them.
r.Use(avero.Stack{Secret: cfg.Secret, Logger: log, Engine: engine}.Middleware()...)
type Telemetry ¶
Telemetry holds the tracer, the meter and the logger of one application. It is a component, so Stop flushes the exporters.
func NewTelemetry ¶
func NewTelemetry(cfg BaseConfig, opts ...TelemetryOption) (*Telemetry, error)
NewTelemetry builds the telemetry provider from the OTEL_* variables. See telemetry.New.
type TelemetryOption ¶
TelemetryOption configures the telemetry provider.
type ViewComponent ¶
ViewComponent renders itself. A templ component satisfies it. The root package already holds Component for the lifecycle contract of the host, so the view name carries the View prefix here.
func CSRFField ¶
func CSRFField() ViewComponent
CSRFField returns the hidden field that an unsafe form must carry.
The SDD names it CSRF. The root package already holds CSRF for the middleware, so the field carries the longer name here. A component calls view.CSRF.
type Wiring ¶ added in v0.4.0
type Wiring struct {
// Router holds the routes of the application. State it or state the
// Handler, and not both.
Router *Router
// Handler serves the requests of an application that holds a router of
// another library. State it or state the Router, and not both.
//
// The inspection commands read the routes of an Avero router, so
// `avero routes` and `avero openapi` report nothing for such an
// application. `avero doctor` reads the configuration and the checks, so
// it works for both.
Handler http.Handler
// Modules holds the module set. Serve reads the migrations of each
// module from it. An application that states no module holds no module
// set, and the field stays nil.
Modules *ModuleSet
// Components are the parts of the application that hold a lifecycle,
// such as an emailer, a blob store or a cache. Serve starts them in this
// order and stops them in reverse order.
//
// A constructor must not dial, connect or read a file, because wire also
// runs for an inspection command with a nil engine and a zero
// configuration. Build the value in the constructor. Connect in Start.
Components []Component
// Checks are the boot checks of the application. Serve runs them before
// the process serves, and `avero doctor` reports them. See DX-8.
//
// A check runs before every component starts. A check that depends on a
// component must open its own connection and close it, and must not
// assume the connection that Start of that component opened.
Checks []Check
}
Wiring is what wire builds. Serve reads it.
An application states its routes in one of two ways. It states the Router, which is the whole host: the typed routes, the module system and the inspection commands. Or it states the Handler, which is any http.Handler, such as a chi router or a mux of the standard library. An application that states the Handler keeps the lifecycle, the configuration, the boot checks and `avero doctor`, and it keeps its own router.
The Modules, the Components and the Checks are optional, so a simple application states one field.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package assets holds the asset pipeline, S11.
|
Package assets holds the asset pipeline, S11. |
|
Package auth holds the auth-all glue of Avero: the user and the session of a request.
|
Package auth holds the auth-all glue of Avero: the user and the session of a request. |
|
cli
module
|
|
|
Package codegen writes the binding and the validation of each handler input as plain Go.
|
Package codegen writes the binding and the validation of each handler input as plain Go. |
|
client
Package client holds the HTTP client generator and the runtime that its output calls, S13.
|
Package client holds the HTTP client generator and the runtime that its output calls, S13. |
|
client/internal/example
Package example holds the client that the tests of the generator drive.
|
Package example holds the client that the tests of the generator drive. |
|
internal/example
Package example is the fixture of the generator.
|
Package example is the fixture of the generator. |
|
Package config loads a configuration struct from environment variables.
|
Package config loads a configuration struct from environment variables. |
|
Package db holds the drel glue of Avero: the transaction middleware, the transaction of a request and the repository of that transaction.
|
Package db holds the drel glue of Avero: the transaction middleware, the transaction of a request and the repository of that transaction. |
|
Package ds holds the Datastar adapter, S12.
|
Package ds holds the Datastar adapter, S12. |
|
Package host owns the lifecycle of an Avero application.
|
Package host owns the lifecycle of an Avero application. |
|
Package htmx holds the htmx adapter, S12.
|
Package htmx holds the htmx adapter, S12. |
|
internal
|
|
|
budget
Package budget records a development experience measurement in the artifacts of the repository.
|
Package budget records a development experience measurement in the artifacts of the repository. |
|
cmd/averogen
command
Command averogen writes the binding and the validation of each handler input, and the implementation of each client interface.
|
Command averogen writes the binding and the validation of each handler input, and the implementation of each client interface. |
|
inspect
Package inspect runs an inspection command of an application and returns the JSON document that it printed.
|
Package inspect runs an inspection command of an application and returns the JSON document that it printed. |
|
migrations
Package migrations reads the migration files of an application and the rows that drel already applied.
|
Package migrations reads the migration files of an application and the rows that drel already applied. |
|
sse
Package sse writes a server sent event stream.
|
Package sse writes a server sent event stream. |
|
Package module holds the module contract and the module inspection, S6.
|
Package module holds the module contract and the module inspection, S6. |
|
Package openapi writes the OpenAPI description of an application, S13.
|
Package openapi writes the OpenAPI description of an application, S13. |
|
Package router builds an http.Handler from typed handlers.
|
Package router builds an http.Handler from typed handlers. |
|
Package telemetry wires OpenTelemetry traces and metrics, and log/slog.
|
Package telemetry wires OpenTelemetry traces and metrics, and log/slog. |
|
Package view holds the helpers that a server rendered page needs, S10.
|
Package view holds the helpers that a server rendered page needs, S10. |