Documentation
¶
Overview ¶
Package vial provides a small, net/http-compatible web application kernel with error-returning handlers, middleware, request helpers, and graceful serving.
Index ¶
- func StatusCode(err error) int
- type App
- func (app *App) Build() error
- func (app *App) Delete(path string, handler Handler)
- func (app *App) Get(path string, handler Handler)
- func (app *App) Group(prefix string) *Group
- func (app *App) Handle(method, path string, handler Handler)
- func (app *App) HandleHTTP(pattern string, handler http.Handler)
- func (app *App) Options(path string, handler Handler)
- func (app *App) Patch(path string, handler Handler)
- func (app *App) Post(path string, handler Handler)
- func (app *App) Put(path string, handler Handler)
- func (app *App) Run(contextValue context.Context, address string) error
- func (app *App) Serve(contextValue context.Context, listener net.Listener) error
- func (app *App) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (app *App) SetErrorHandler(handler ErrorHandler)
- func (app *App) Use(middleware ...Middleware)
- type Context
- func (context *Context) App() *App
- func (context *Context) BindJSON(destination any) error
- func (context *Context) BytesWritten() int64
- func (context *Context) Committed() bool
- 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) Route() *Route
- func (context *Context) Set(key string, value any)
- func (context *Context) SetLogger(logger *slog.Logger)
- 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)
- func (group *Group) Get(path string, handler Handler)
- func (group *Group) Group(prefix string) *Group
- func (group *Group) Handle(method, path string, handler Handler)
- func (group *Group) Options(path string, handler Handler)
- func (group *Group) Patch(path string, handler Handler)
- func (group *Group) Post(path string, handler Handler)
- func (group *Group) Put(path string, handler Handler)
- 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 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 Middleware
- type Option
- func WithDisallowUnknownJSONFields(enabled bool) Option
- func WithIdleTimeout(timeout time.Duration) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxBodySize(bytes int64) Option
- func WithReadHeaderTimeout(timeout time.Duration) Option
- func WithReadTimeout(timeout time.Duration) Option
- func WithShutdownTimeout(timeout time.Duration) Option
- func WithWriteTimeout(timeout time.Duration) Option
- type ResponseWriter
- func (writer *ResponseWriter) BytesWritten() int64
- func (writer *ResponseWriter) Committed() bool
- func (writer *ResponseWriter) Flush()
- func (writer *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (writer *ResponseWriter) Push(target string, options *http.PushOptions) error
- func (writer *ResponseWriter) ReadFrom(reader io.Reader) (int64, error)
- 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 Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) HandleHTTP ¶
HandleHTTP mounts a standard-library handler using a native ServeMux pattern. Examples include "/metrics", "GET /health", and "api.example.com/".
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)
func (*App) SetErrorHandler ¶
func (app *App) SetErrorHandler(handler ErrorHandler)
func (*App) Use ¶
func (app *App) Use(middleware ...Middleware)
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 (*Context) BindJSON ¶
BindJSON decodes a single JSON value into destination using the application's body limit and unknown-field policy.
func (*Context) BytesWritten ¶
func (*Context) Response ¶
func (context *Context) Response() http.ResponseWriter
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) Use ¶
func (group *Group) Use(middleware ...Middleware)
type HTTPError ¶
HTTPError is an application error with a stable HTTP representation.
func BadRequest ¶
func InternalServerError ¶
func NewHTTPError ¶
func RequestEntityTooLarge ¶
func Unauthorized ¶
func UnsupportedMediaType ¶
type Handler ¶
Handler is the framework's HTTP handler contract. Returning errors keeps transport error rendering centralized and makes middleware composition simple.
type Middleware ¶
Middleware wraps a Handler with cross-cutting behavior.
type Option ¶
type Option func(*config)
Option configures an App.
func WithIdleTimeout ¶
func WithLogger ¶
func WithMaxBodySize ¶
func WithReadHeaderTimeout ¶
func WithReadTimeout ¶
func WithShutdownTimeout ¶
func WithWriteTimeout ¶
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
func (*ResponseWriter) Committed ¶
func (writer *ResponseWriter) Committed() bool
func (*ResponseWriter) Flush ¶
func (writer *ResponseWriter) Flush()
func (*ResponseWriter) Hijack ¶
func (writer *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*ResponseWriter) Push ¶
func (writer *ResponseWriter) Push(target string, options *http.PushOptions) error
func (*ResponseWriter) ReadFrom ¶
func (writer *ResponseWriter) ReadFrom(reader io.Reader) (int64, error)
func (*ResponseWriter) Status ¶
func (writer *ResponseWriter) Status() int
func (*ResponseWriter) Unwrap ¶
func (writer *ResponseWriter) Unwrap() http.ResponseWriter
func (*ResponseWriter) WriteHeader ¶
func (writer *ResponseWriter) WriteHeader(status int)