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 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 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 UnpackMigrations(fsys fs.FS, root string) (string, func(), error)
- func WithAPI(api API) router.Option
- func WithForm(page func(c *Ctx, f *Fields) ViewComponent) 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 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 Recover(l *slog.Logger) Middleware
- func RequestID() Middleware
- func Transaction(e *drel.Engine) Middleware
- type MigrationModule
- type Migrator
- type ModelDesc
- type Module
- type ModuleReport
- type ModuleSet
- 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 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 Source
- type Tag
- type Telemetry
- type TelemetryOption
- type Toast
- type Validator
- type ViewComponent
- type ViewFunc
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 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 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 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 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()
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 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 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 Transaction ¶
func Transaction(e *drel.Engine) Middleware
Transaction opens a drel transaction and decides the commit from the response.
type MigrationModule ¶
type MigrationModule = module.MigrationModule
MigrationModule contributes migration files.
type ModuleReport ¶
ModuleReport lists the contribution of every module.
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 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 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.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package assets holds the asset pipeline, S11.
|
Package assets holds the asset pipeline, S11. |
|
cli
module
|
|
|
cmd
|
|
|
avero
command
Command avero writes an application, generates its code, proves its configuration and builds it.
|
Command avero writes an application, generates its code, proves its configuration and builds it. |
|
avero/dev
Package dev holds the development loop, S15.
|
Package dev holds the development loop, S15. |
|
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 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. |
|
cli
Package cli holds the commands of the avero binary, S14.
|
Package cli holds the commands of the avero binary, S14. |
|
cmd/averoexamples
command
Command averoexamples writes the three reference applications into examples/, and proves that they match the templates of the scaffolder.
|
Command averoexamples writes the three reference applications into examples/, and proves that they match the templates of the scaffolder. |
|
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 mcp serves the agent surface of an application over stdio, S16.
|
Package mcp serves the agent surface of an application over stdio, S16. |
|
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 scaffold writes a new Avero application, S14.
|
Package scaffold writes a new Avero application, S14. |
|
Package telemetry wires OpenTelemetry traces and metrics, and log/slog.
|
Package telemetry wires OpenTelemetry traces and metrics, and log/slog. |
|
Package verify runs the gate of an application and reports one record for each step, S16.
|
Package verify runs the gate of an application and reports one record for each step, S16. |
|
Package view holds the helpers that a server rendered page needs, S10.
|
Package view holds the helpers that a server rendered page needs, S10. |