Documentation
¶
Overview ¶
Package vial is a small web application framework built on net/http. It adds error-returning handlers, middleware, request helpers, and graceful shutdown.
Index ¶
- Variables
- func PrefersRespondAsync(header string) bool
- func StatusCode(err error) int
- type App
- func (app *App) Async(executor AsyncExecutor)
- func (app *App) AsyncExecutor() AsyncExecutor
- func (app *App) Build() error
- func (app *App) Delete(path string, handler Handler, options ...RouteOption)
- func (app *App) Get(path string, handler Handler, options ...RouteOption)
- func (app *App) Go(name string, task Task, options ...TaskOption)
- func (app *App) Group(prefix string) *Group
- func (app *App) Handle(method, path string, handler Handler, options ...RouteOption)
- func (app *App) HandleHTTP(pattern string, handler http.Handler, options ...RouteOption)
- func (app *App) Health(path string)
- func (app *App) OnStart(hooks ...LifecycleHook)
- func (app *App) OnStop(hooks ...LifecycleHook)
- func (app *App) Options(path string, handler Handler, options ...RouteOption)
- func (app *App) Patch(path string, handler Handler, options ...RouteOption)
- func (app *App) Post(path string, handler Handler, options ...RouteOption)
- func (app *App) Put(path string, handler Handler, options ...RouteOption)
- func (app *App) Readiness(path string, checks ...HealthCheck)
- func (app *App) Register(modules ...Module) error
- func (app *App) Routes() ([]Route, error)
- func (app *App) Run(contextValue context.Context, address string) error
- func (app *App) Serve(contextValue context.Context, listener net.Listener) (serveErr error)
- func (app *App) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (app *App) SetErrorHandler(handler ErrorHandler)
- func (app *App) Use(middleware ...Middleware)
- type AsyncExecutor
- type AsyncHandler
- type AsyncJob
- type AsyncLifecycleExecutor
- type AsyncMetrics
- type AsyncMetricsProvider
- type AsyncPreference
- type AsyncWaiter
- type BindingError
- type Context
- func (contextValue *Context) Accepted(operation *Operation) error
- func (contextValue *Context) AcceptedAt(operation *Operation, statusURL string) error
- func (context *Context) App() *App
- func (contextValue *Context) Async() AsyncExecutor
- func (contextValue *Context) Await(operation *Operation, maximum time.Duration) (current *Operation, completed bool, err error)
- func (context *Context) Bind(destination any) error
- func (context *Context) BindCookie(destination any) error
- func (context *Context) BindForm(destination any) error
- func (context *Context) BindHeader(destination any) error
- func (context *Context) BindJSON(destination any) error
- func (context *Context) BindPath(destination any) error
- func (context *Context) BindQuery(destination any) error
- func (context *Context) BytesWritten() int64
- func (context *Context) ClientIP() (netip.Addr, error)
- func (context *Context) Committed() bool
- func (context *Context) Flush() error
- func (context *Context) FormFile(name string) (multipart.File, *multipart.FileHeader, error)
- func (context *Context) FormValue(name string) (string, error)
- func (context *Context) Get(key string) (any, bool)
- func (context *Context) Header(name string) string
- func (context *Context) JSON(status int, value any) error
- func (context *Context) Logger() *slog.Logger
- func (context *Context) NoContent(status int) error
- func (context *Context) Param(name string) string
- func (context *Context) Query(name string) string
- func (context *Context) Redirect(status int, location string) error
- func (context *Context) Request() *http.Request
- func (context *Context) Response() http.ResponseWriter
- func (context *Context) ResponseController() *http.ResponseController
- func (context *Context) Route() *Route
- func (context *Context) Set(key string, value any)
- func (context *Context) SetLogger(logger *slog.Logger)
- func (context *Context) SetWriteDeadline(deadline time.Time) error
- func (context *Context) Status() int
- func (context *Context) Text(status int, value string) error
- type ErrorHandler
- type Group
- func (group *Group) Delete(path string, handler Handler, options ...RouteOption)
- func (group *Group) Get(path string, handler Handler, options ...RouteOption)
- func (group *Group) Group(prefix string) *Group
- func (group *Group) Handle(method, path string, handler Handler, options ...RouteOption)
- func (group *Group) HandleHTTP(pattern string, handler http.Handler, options ...RouteOption)
- func (group *Group) Options(path string, handler Handler, options ...RouteOption)
- func (group *Group) Patch(path string, handler Handler, options ...RouteOption)
- func (group *Group) Post(path string, handler Handler, options ...RouteOption)
- func (group *Group) Put(path string, handler Handler, options ...RouteOption)
- func (group *Group) Use(middleware ...Middleware)
- type HTTPError
- func BadRequest(code, message string) *HTTPError
- func Conflict(code, message string) *HTTPError
- func Forbidden(code, message string) *HTTPError
- func InternalServerError(cause error) *HTTPError
- func MethodNotAllowed(code, message string) *HTTPError
- func NewHTTPError(status int, code, message string) *HTTPError
- func NotFound(code, message string) *HTTPError
- func RequestEntityTooLarge(code, message string) *HTTPError
- func Unauthorized(code, message string) *HTTPError
- func UnsupportedMediaType(code, message string) *HTTPError
- func WrapHTTPError(status int, code, message string, cause error) *HTTPError
- type Handler
- type HealthCheck
- type LifecycleHook
- type Middleware
- type Module
- type Operation
- type OperationAuthorizer
- type OperationError
- type OperationStatus
- type Option
- func WithBaseContext(baseContext func(net.Listener) context.Context) Option
- func WithConnContext(connContext func(context.Context, net.Conn) context.Context) Option
- func WithDisallowUnknownJSONFields(enabled bool) Option
- func WithHTTPProtocols(protocols *http.Protocols) Option
- func WithHealthCheckTimeout(timeout time.Duration) Option
- func WithIdleTimeout(timeout time.Duration) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxBodySize(bytes int64) Option
- func WithMaxHeaderBytes(bytes int) Option
- func WithReadHeaderTimeout(timeout time.Duration) Option
- func WithReadTimeout(timeout time.Duration) Option
- func WithServerErrorLog(logger *log.Logger) Option
- func WithShutdownTimeout(timeout time.Duration) Option
- func WithTrustedProxies(values ...string) Option
- func WithWriteTimeout(timeout time.Duration) Option
- type Registrar
- func (registrar *Registrar) Go(name string, task Task, options ...TaskOption)
- func (registrar *Registrar) Group(prefix string) *Group
- func (registrar *Registrar) Handle(method, path string, handler Handler, options ...RouteOption)
- func (registrar *Registrar) HandleHTTP(pattern string, handler http.Handler, options ...RouteOption)
- func (registrar *Registrar) Health(path string)
- func (registrar *Registrar) OnStart(hooks ...LifecycleHook)
- func (registrar *Registrar) OnStop(hooks ...LifecycleHook)
- func (registrar *Registrar) Readiness(path string, checks ...HealthCheck)
- func (registrar *Registrar) Use(middleware ...Middleware)
- type ResponseWriter
- func (writer *ResponseWriter) BytesWritten() int64
- func (writer *ResponseWriter) Committed() bool
- func (writer *ResponseWriter) Status() int
- func (writer *ResponseWriter) Unwrap() http.ResponseWriter
- func (writer *ResponseWriter) Write(data []byte) (int, error)
- func (writer *ResponseWriter) WriteHeader(status int)
- type RetryPolicy
- type Route
- type RouteOption
- type SubmitRequest
- type Task
- type TaskOption
- type Validator
- type ValueKey
Constants ¶
This section is empty.
Variables ¶
var ( ErrAsyncQueueFull = errors.New("async executor queue is full") ErrInvalidOperation = errors.New("invalid async operation") ErrOperationNotFound = errors.New("operation not found") ErrOperationFinished = errors.New("operation is already finished") ErrRetriesUnsupported = errors.New("async executor does not support retries") ErrInvalidPreference = errors.New("invalid Prefer header") )
Functions ¶
func PrefersRespondAsync ¶ added in v0.16.0
PrefersRespondAsync reports whether Prefer requests RFC 7240 respond-async.
func StatusCode ¶
StatusCode returns the HTTP status represented by err, defaulting to 500.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the framework application and implements http.Handler.
func (*App) Async ¶ added in v0.16.0
func (app *App) Async(executor AsyncExecutor)
Async registers the application's executor. Lifecycle executors are started before HTTP serving and drained during application shutdown.
func (*App) AsyncExecutor ¶ added in v0.16.0
func (app *App) AsyncExecutor() AsyncExecutor
AsyncExecutor returns the registered executor, or nil when none is configured.
func (*App) Delete ¶
func (app *App) Delete(path string, handler Handler, options ...RouteOption)
Delete registers a DELETE route.
func (*App) Get ¶
func (app *App) Get(path string, handler Handler, options ...RouteOption)
Get registers a GET route.
func (*App) Go ¶ added in v0.7.0
func (app *App) Go(name string, task Task, options ...TaskOption)
Go registers a named background task. Tasks are critical by default and begin running when the application starts.
func (*App) Handle ¶
func (app *App) Handle(method, path string, handler Handler, options ...RouteOption)
Handle registers a route for an HTTP method and path.
func (*App) HandleHTTP ¶
func (app *App) HandleHTTP(pattern string, handler http.Handler, options ...RouteOption)
HandleHTTP mounts a standard-library handler using a native ServeMux pattern. Examples include "/metrics", "GET /health", and "api.example.com/".
func (*App) OnStart ¶ added in v0.4.0
func (app *App) OnStart(hooks ...LifecycleHook)
OnStart registers hooks that run in registration order before components start.
func (*App) OnStop ¶ added in v0.4.0
func (app *App) OnStop(hooks ...LifecycleHook)
OnStop registers hooks that run in reverse registration order after components stop.
func (*App) Options ¶
func (app *App) Options(path string, handler Handler, options ...RouteOption)
Options registers an OPTIONS route.
func (*App) Patch ¶
func (app *App) Patch(path string, handler Handler, options ...RouteOption)
Patch registers a PATCH route.
func (*App) Post ¶
func (app *App) Post(path string, handler Handler, options ...RouteOption)
Post registers a POST route.
func (*App) Put ¶
func (app *App) Put(path string, handler Handler, options ...RouteOption)
Put registers a PUT route.
func (*App) Readiness ¶ added in v0.15.0
func (app *App) Readiness(path string, checks ...HealthCheck)
Readiness registers an endpoint that is ready only while the application is running and every check succeeds within its configured timeout.
func (*App) Routes ¶ added in v0.2.0
Routes validates the application and returns registered route metadata in registration order. The returned slice does not share state with the app.
func (*App) Run ¶
Run listens on address and serves until the parent context or a supported OS shutdown signal is received.
func (*App) Serve ¶
Serve runs the application on an existing listener. This is useful for tests and for callers that need custom listener configuration.
func (*App) ServeHTTP ¶
func (app *App) ServeHTTP(writer http.ResponseWriter, request *http.Request)
ServeHTTP implements http.Handler and builds the application on first use.
func (*App) SetErrorHandler ¶
func (app *App) SetErrorHandler(handler ErrorHandler)
SetErrorHandler replaces the application's error renderer.
func (*App) Use ¶
func (app *App) Use(middleware ...Middleware)
Use adds middleware to the application-wide chain.
type AsyncExecutor ¶ added in v0.16.0
type AsyncExecutor interface {
Submit(context.Context, SubmitRequest) (*Operation, error)
Get(context.Context, string) (*Operation, error)
Cancel(context.Context, string) error
}
AsyncExecutor submits, retrieves, and cancels asynchronous operations.
type AsyncHandler ¶ added in v0.16.0
AsyncHandler processes one operation delivery.
type AsyncJob ¶ added in v0.16.0
type AsyncJob interface {
ID() string
Name() string
Decode(any) error
Metadata() map[string]string
Progress(context.Context, int) error
}
AsyncJob is immutable application-level input supplied to an operation handler.
type AsyncLifecycleExecutor ¶ added in v0.16.0
type AsyncLifecycleExecutor interface {
AsyncExecutor
Start(context.Context) error
Done() <-chan error
Shutdown(context.Context) error
}
AsyncLifecycleExecutor is an executor managed by the Vial application lifecycle. External durable executors may implement only AsyncExecutor.
type AsyncMetrics ¶ added in v0.16.0
type AsyncMetrics struct {
SubmittedTotal uint64
CompletedTotal uint64
FailedTotal uint64
CancelledTotal uint64
RetriedTotal uint64
QueueDepth int64
Running int64
DurationSecondsTotal float64
DurationCount uint64
QueueWaitSecondsTotal float64
QueueWaitCount uint64
}
AsyncMetrics is a point-in-time executor metrics snapshot.
type AsyncMetricsProvider ¶ added in v0.16.0
type AsyncMetricsProvider interface {
Metrics(context.Context) (AsyncMetrics, error)
}
AsyncMetricsProvider supplies executor metrics.
type AsyncPreference ¶ added in v0.16.0
AsyncPreference is the RFC 7240 asynchronous preference requested by a client.
func ParsePrefer ¶ added in v0.16.0
func ParsePrefer(header string) (AsyncPreference, error)
ParsePrefer parses respond-async and wait=n while ignoring unknown preferences.
type AsyncWaiter ¶ added in v0.16.0
AsyncWaiter efficiently waits for an operation state change or completion.
type BindingError ¶ added in v0.4.0
BindingError identifies the request field that could not be bound.
func (*BindingError) Error ¶ added in v0.4.0
func (err *BindingError) Error() string
Error describes the binding source, field, and cause.
func (*BindingError) Unwrap ¶ added in v0.4.0
func (err *BindingError) Unwrap() error
Unwrap returns the binding failure cause.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context contains request-scoped framework state while retaining direct access to the standard net/http request and response writer.
func ContextFromRequest ¶ added in v0.15.0
ContextFromRequest returns the Vial context attached to a routed request. It lets standard net/http handlers access route metadata without exported context keys that could collide with application values.
func (*Context) Accepted ¶ added in v0.16.0
Accepted writes the conventional 202 response for an asynchronous operation.
func (*Context) AcceptedAt ¶ added in v0.16.0
AcceptedAt writes a 202 response whose Location points at statusURL.
func (*Context) Async ¶ added in v0.16.0
func (contextValue *Context) Async() AsyncExecutor
Async returns the application's registered executor.
func (*Context) Await ¶ added in v0.16.0
func (contextValue *Context) Await(operation *Operation, maximum time.Duration) (current *Operation, completed bool, err error)
Await waits up to the client preference and server maximum. completed is true only when the returned operation reached a terminal state.
func (*Context) Bind ¶ added in v0.4.0
Bind combines tagged path, query, header, cookie, JSON, and form input.
func (*Context) BindCookie ¶ added in v0.4.0
BindCookie binds request cookies to fields tagged with `cookie`.
func (*Context) BindForm ¶ added in v0.3.0
BindForm binds URL-encoded or multipart form fields to primitive struct fields tagged with `form`. Repeated values bind to slices.
func (*Context) BindHeader ¶ added in v0.4.0
BindHeader binds request headers to fields tagged with `header`.
func (*Context) BindJSON ¶
BindJSON decodes a single JSON value into destination using the application's body limit and unknown-field policy.
func (*Context) BindPath ¶ added in v0.4.0
BindPath binds route parameters to fields tagged with `path`.
func (*Context) BindQuery ¶ added in v0.3.0
BindQuery binds query parameters to primitive struct fields tagged with `query`. Repeated values bind to slices.
func (*Context) BytesWritten ¶
BytesWritten returns the response body bytes written so far.
func (*Context) ClientIP ¶ added in v0.15.0
ClientIP returns the direct peer unless it is an explicitly trusted proxy. Trusted proxy chains are evaluated from the application outward, stopping at the first untrusted address.
func (*Context) Flush ¶ added in v0.15.0
Flush sends buffered response data when the server supports streaming.
func (*Context) FormFile ¶ added in v0.3.0
FormFile returns the first uploaded file for name. The caller must close the file. Vial removes any temporary multipart files after the request finishes.
func (*Context) FormValue ¶ added in v0.10.0
FormValue returns the first URL-encoded or multipart form value for name.
func (*Context) Response ¶
func (context *Context) Response() http.ResponseWriter
Response returns the tracked HTTP response writer.
func (*Context) ResponseController ¶ added in v0.15.0
func (context *Context) ResponseController() *http.ResponseController
ResponseController exposes standard-library optional response operations.
func (*Context) SetWriteDeadline ¶ added in v0.15.0
SetWriteDeadline sets the response write deadline when supported.
type ErrorHandler ¶
ErrorHandler renders errors returned by handlers or middleware.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group applies a common path prefix and middleware chain to related routes.
func (*Group) Delete ¶
func (group *Group) Delete(path string, handler Handler, options ...RouteOption)
Delete registers a DELETE route in the group.
func (*Group) Get ¶
func (group *Group) Get(path string, handler Handler, options ...RouteOption)
Get registers a GET route in the group.
func (*Group) Handle ¶
func (group *Group) Handle(method, path string, handler Handler, options ...RouteOption)
Handle registers a route in the group.
func (*Group) HandleHTTP ¶ added in v0.15.0
func (group *Group) HandleHTTP(pattern string, handler http.Handler, options ...RouteOption)
HandleHTTP registers a standard library handler under the group's prefix.
func (*Group) Options ¶
func (group *Group) Options(path string, handler Handler, options ...RouteOption)
Options registers an OPTIONS route in the group.
func (*Group) Patch ¶
func (group *Group) Patch(path string, handler Handler, options ...RouteOption)
Patch registers a PATCH route in the group.
func (*Group) Post ¶
func (group *Group) Post(path string, handler Handler, options ...RouteOption)
Post registers a POST route in the group.
func (*Group) Put ¶
func (group *Group) Put(path string, handler Handler, options ...RouteOption)
Put registers a PUT route in the group.
func (*Group) Use ¶
func (group *Group) Use(middleware ...Middleware)
Use adds middleware to routes subsequently registered through the group.
type HTTPError ¶
HTTPError is an application error with a stable HTTP representation.
func BadRequest ¶
BadRequest creates a 400 HTTP error.
func InternalServerError ¶
InternalServerError creates a generic 500 HTTP error that retains cause.
func MethodNotAllowed ¶ added in v0.3.0
MethodNotAllowed creates a 405 HTTP error.
func NewHTTPError ¶
NewHTTPError creates an HTTP error with a stable status, code, and message.
func RequestEntityTooLarge ¶
RequestEntityTooLarge creates a 413 HTTP error.
func Unauthorized ¶
Unauthorized creates a 401 HTTP error.
func UnsupportedMediaType ¶
UnsupportedMediaType creates a 415 HTTP error.
func WrapHTTPError ¶
WrapHTTPError creates an HTTP error that retains cause.
type Handler ¶
Handler is the framework's HTTP handler contract. Returning errors keeps transport error rendering centralized and makes middleware composition simple.
func AsyncMetricsHandler ¶ added in v0.16.0
func AsyncMetricsHandler(provider AsyncMetricsProvider) Handler
AsyncMetricsHandler exposes dependency-free Prometheus/OpenMetrics metrics.
func OperationCancelHandler ¶ added in v0.16.0
func OperationCancelHandler(executor AsyncExecutor, authorize OperationAuthorizer) Handler
OperationCancelHandler returns a cancellation handler for a route containing {id}.
func OperationStatusHandler ¶ added in v0.16.0
func OperationStatusHandler(executor AsyncExecutor, authorize OperationAuthorizer) Handler
OperationStatusHandler returns a polling handler for a route containing {id}.
type HealthCheck ¶ added in v0.15.0
HealthCheck reports whether one readiness dependency can currently serve.
type LifecycleHook ¶ added in v0.4.0
LifecycleHook runs while the application starts or stops.
type Middleware ¶
Middleware wraps a Handler with cross-cutting behavior.
type Operation ¶ added in v0.16.0
type Operation struct {
ID string `json:"id"`
Name string `json:"name"`
Status OperationStatus `json:"status"`
Progress int `json:"progress"`
CreatedAt time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at"`
Result any `json:"result"`
Error *OperationError `json:"error"`
Metadata map[string]string `json:"-"`
Attempt int `json:"attempt"`
MaxAttempts int `json:"max_attempts"`
NextAttemptAt *time.Time `json:"next_attempt_at"`
}
Operation describes submitted background work.
type OperationAuthorizer ¶ added in v0.16.0
OperationAuthorizer applies application ownership rules before status or cancellation is exposed. Helpers require one to avoid globally readable IDs.
type OperationError ¶ added in v0.16.0
OperationError is the safe, client-visible reason an operation failed.
func (*OperationError) Error ¶ added in v0.16.0
func (operationError *OperationError) Error() string
type OperationStatus ¶ added in v0.16.0
type OperationStatus string
OperationStatus is the current state of an asynchronous operation.
const ( OperationPending OperationStatus = "pending" OperationRunning OperationStatus = "running" OperationRetrying OperationStatus = "retrying" OperationSucceeded OperationStatus = "succeeded" OperationFailed OperationStatus = "failed" OperationCancelled OperationStatus = "cancelled" )
func (OperationStatus) Terminal ¶ added in v0.16.0
func (status OperationStatus) Terminal() bool
Terminal reports whether no further state transition is possible.
type Option ¶
type Option func(*config)
Option configures an App.
func WithBaseContext ¶ added in v0.15.0
WithBaseContext sets http.Server.BaseContext.
func WithConnContext ¶ added in v0.15.0
WithConnContext sets http.Server.ConnContext.
func WithDisallowUnknownJSONFields ¶
WithDisallowUnknownJSONFields controls rejection of unknown JSON fields.
func WithHTTPProtocols ¶ added in v0.18.0
WithHTTPProtocols sets http.Server.Protocols.
func WithHealthCheckTimeout ¶ added in v0.15.0
WithHealthCheckTimeout sets the maximum duration of each readiness check.
func WithIdleTimeout ¶
WithIdleTimeout sets the HTTP server keep-alive idle timeout.
func WithLogger ¶
WithLogger sets the application logger.
func WithMaxBodySize ¶
WithMaxBodySize sets the request body limit when bytes is positive.
func WithMaxHeaderBytes ¶ added in v0.15.0
WithMaxHeaderBytes sets the maximum request-header size.
func WithReadHeaderTimeout ¶
WithReadHeaderTimeout sets the HTTP server header-read timeout.
func WithReadTimeout ¶
WithReadTimeout sets the HTTP server request-read timeout.
func WithServerErrorLog ¶ added in v0.15.0
WithServerErrorLog sets http.Server.ErrorLog.
func WithShutdownTimeout ¶
WithShutdownTimeout sets the graceful shutdown deadline when timeout is positive.
func WithTrustedProxies ¶ added in v0.15.0
WithTrustedProxies trusts forwarding headers only when the direct peer matches one of the listed IPs or CIDRs. The default trusts none.
func WithWriteTimeout ¶
WithWriteTimeout sets the HTTP server response-write timeout.
type Registrar ¶ added in v0.4.0
type Registrar struct {
// contains filtered or unexported fields
}
Registrar exposes the route registration surface available to modules.
func (*Registrar) Go ¶ added in v0.15.0
func (registrar *Registrar) Go(name string, task Task, options ...TaskOption)
Go registers a supervised module background task.
func (*Registrar) Handle ¶ added in v0.4.0
func (registrar *Registrar) Handle(method, path string, handler Handler, options ...RouteOption)
Handle registers a module route.
func (*Registrar) HandleHTTP ¶ added in v0.4.0
func (registrar *Registrar) HandleHTTP(pattern string, handler http.Handler, options ...RouteOption)
HandleHTTP mounts a standard-library handler in the module.
func (*Registrar) OnStart ¶ added in v0.15.0
func (registrar *Registrar) OnStart(hooks ...LifecycleHook)
OnStart registers module startup hooks.
func (*Registrar) OnStop ¶ added in v0.15.0
func (registrar *Registrar) OnStop(hooks ...LifecycleHook)
OnStop registers module shutdown hooks.
func (*Registrar) Readiness ¶ added in v0.15.0
func (registrar *Registrar) Readiness(path string, checks ...HealthCheck)
Readiness registers a module readiness endpoint.
func (*Registrar) Use ¶ added in v0.4.0
func (registrar *Registrar) Use(middleware ...Middleware)
Use adds middleware to every route registered by the module.
type ResponseWriter ¶
type ResponseWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
ResponseWriter tracks response state while retaining access to the underlying standard-library writer through Unwrap.
func (*ResponseWriter) BytesWritten ¶
func (writer *ResponseWriter) BytesWritten() int64
BytesWritten returns the response body bytes written so far.
func (*ResponseWriter) Committed ¶
func (writer *ResponseWriter) Committed() bool
Committed reports whether response headers were written.
func (*ResponseWriter) Status ¶
func (writer *ResponseWriter) Status() int
Status returns the written status or 200 before commitment.
func (*ResponseWriter) Unwrap ¶
func (writer *ResponseWriter) Unwrap() http.ResponseWriter
Unwrap returns the underlying standard-library response writer.
func (*ResponseWriter) Write ¶
func (writer *ResponseWriter) Write(data []byte) (int, error)
Write writes response data and records its size.
func (*ResponseWriter) WriteHeader ¶
func (writer *ResponseWriter) WriteHeader(status int)
WriteHeader records and writes the first response status.
type RetryPolicy ¶ added in v0.16.0
RetryPolicy configures durable redelivery after transient worker failures. Its zero value permits one attempt and therefore disables retries.
type Route ¶
type Route struct {
Method string
Path string
Pattern string
Name string
Module string
MiddlewareCount int
Parameters []string
}
Route contains metadata for a registered endpoint.
type RouteOption ¶ added in v0.4.0
type RouteOption struct {
// contains filtered or unexported fields
}
RouteOption configures route metadata.
func RouteMiddleware ¶ added in v0.15.0
func RouteMiddleware(middleware ...Middleware) RouteOption
RouteMiddleware applies middleware only to the configured route.
func RouteName ¶ added in v0.4.0
func RouteName(name string) RouteOption
RouteName assigns a globally unique, stable observability and diagnostics identifier. Route names are not used for URL generation.
type SubmitRequest ¶ added in v0.16.0
type SubmitRequest struct {
Name string
Payload any
IdempotencyKey string
IdempotencyScope string
Metadata map[string]string
Retry RetryPolicy
}
SubmitRequest contains serializable, application-level data for an operation. IdempotencyScope must identify the authenticated owner when IdempotencyKey is set.
type Task ¶ added in v0.7.0
Task is application work that runs until its context is canceled or it fails.
type TaskOption ¶ added in v0.7.0
type TaskOption struct {
// contains filtered or unexported fields
}
TaskOption configures a background task.
func NonCritical ¶ added in v0.7.0
func NonCritical() TaskOption
NonCritical keeps the application running when the task exits or fails.
type Validator ¶ added in v0.10.0
type Validator interface {
Validate() error
}
Validator validates bound request data. Returning a *fault.Error preserves its field errors for response handling and rendering.
type ValueKey ¶ added in v0.15.0
type ValueKey[T any] struct { // contains filtered or unexported fields }
ValueKey is a collision-safe request value key. Keep and reuse the pointer returned by NewValueKey; identity, not the display name, selects the value.
func NewValueKey ¶ added in v0.15.0
NewValueKey creates a typed request value key.
func (*ValueKey[T]) FromRequest ¶ added in v0.15.0
FromRequest returns the same typed value through the underlying request.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package async contains Vial's bounded in-memory executor.
|
Package async contains Vial's bounded in-memory executor. |
|
cmd
|
|
|
vial
command
|
|
|
Package config loads typed application configuration from explicit files and environment variables.
|
Package config loads typed application configuration from explicit files and environment variables. |
|
contrib
|
|
|
asyncpostgres
Package asyncpostgres implements Vial's durable PostgreSQL executor.
|
Package asyncpostgres implements Vial's durable PostgreSQL executor. |
|
examples
|
|
|
async
command
|
|
|
config
command
|
|
|
events
command
|
|
|
hello
command
|
|
|
json-api
command
|
|
|
modules
command
|
|
|
sse
command
|
|
|
tasks
command
|
|
|
upload
command
|
|
|
web
command
|
|
|
Package fault defines transport-neutral application errors.
|
Package fault defines transport-neutral application errors. |
|
internal
|
|
|
load
Package load runs bounded HTTP load checks for the vial command.
|
Package load runs bounded HTTP load checks for the vial command. |
|
Package middleware contains the framework's optional default HTTP middleware.
|
Package middleware contains the framework's optional default HTTP middleware. |
|
Package render writes html/template output through Vial handlers.
|
Package render writes html/template output through Vial handlers. |
|
Package testkit runs Vial applications through their full lifecycle in HTTP tests.
|
Package testkit runs Vial applications through their full lifecycle in HTTP tests. |
|
vialgrpc
module
|
|
|
vialws
module
|