Documentation
¶
Index ¶
- func Delete[In any, Out any](r Router, pattern string, handler Handler[In, Out], opts ...RouteOption) error
- func Get[In any, Out any](r Router, pattern string, handler Handler[In, Out], opts ...RouteOption) error
- func Options[In any, Out any](r Router, pattern string, handler Handler[In, Out], opts ...RouteOption) error
- func Patch[In any, Out any](r Router, pattern string, handler Handler[In, Out], opts ...RouteOption) error
- func Post[In any, Out any](r Router, pattern string, handler Handler[In, Out], opts ...RouteOption) error
- func Put[In any, Out any](r Router, pattern string, handler Handler[In, Out], opts ...RouteOption) error
- func WS[In any, Msg any](r Router, pattern string, handler WebsocketHandler[In, Msg], ...) error
- type App
- func (a *App) AddErrorObserver(observer func(context.Context, error))
- func (a *App) AddSecurityScheme(name string, scheme SecurityScheme)
- func (a *App) App() *App
- func (a *App) Group(prefix string, mw ...func(http.Handler) http.Handler) *Group
- func (a *App) Handle(method, pattern string, handler http.Handler, route *Route)
- func (a *App) HandleHTTP(method, pattern string, handler http.Handler, opts ...RouteOption)
- func (a *App) Metrics(pattern string, handler http.Handler, opts ...RouteOption)
- func (a *App) Middleware() []func(http.Handler) http.Handler
- func (a *App) OpenAPI(pattern, title, version string)
- func (a *App) OpenAPIDocument(title, version string) *openapi.Document
- func (a *App) OpenAPIHandler(title, version string) http.Handler
- func (a *App) Prefix() string
- func (a *App) RedocUI(pattern, specURL string)
- func (a *App) RedocUIHandler(specURL string) http.Handler
- func (a *App) Routes() []*Route
- func (a *App) Run(addr string) error
- func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *App) Static(prefix, root string, opts ...RouteOption)
- func (a *App) StaticFS(prefix string, fs http.FileSystem, opts ...RouteOption)
- func (a *App) SwaggerUI(pattern, specURL string)
- func (a *App) SwaggerUIHandler(specURL string) http.Handler
- func (a *App) Use(mw ...func(http.Handler) http.Handler)
- func (a *App) WS(pattern string, handler any, opts ...RouteOption) error
- type Binder
- type ContextKey
- type ErrorHandler
- type Event
- type Group
- func (g *Group) App() *App
- func (g *Group) Group(prefix string, mw ...func(http.Handler) http.Handler) *Group
- func (g *Group) Handle(method, pattern string, handler http.Handler, route *Route)
- func (g *Group) HandleHTTP(method, pattern string, handler http.Handler, opts ...RouteOption)
- func (g *Group) Metrics(pattern string, handler http.Handler, opts ...RouteOption)
- func (g *Group) Middleware() []func(http.Handler) http.Handler
- func (g *Group) Prefix() string
- func (g *Group) Static(prefix, root string, opts ...RouteOption)
- func (g *Group) StaticFS(prefix string, fs http.FileSystem, opts ...RouteOption)
- func (g *Group) WS(pattern string, handler any, opts ...RouteOption) error
- type Handler
- type Option
- func WithErrorHandler(h ErrorHandler) Option
- func WithGlobalMiddleware(mw ...func(http.Handler) http.Handler) Option
- func WithMaxMultipartMemory(max int64) Option
- func WithShutdownTimeout(d time.Duration) Option
- func WithStrictHeader() Option
- func WithStrictQuery() Option
- func WithValidator(v Validator) Option
- type Route
- func (r *Route) GetDeprecated() bool
- func (r *Route) GetDescription() string
- func (r *Route) GetInternal() bool
- func (r *Route) GetMethod() string
- func (r *Route) GetOperationID() string
- func (r *Route) GetOutputType() reflect.Type
- func (r *Route) GetPattern() string
- func (r *Route) GetSchema() *bind.Schema
- func (r *Route) GetSecurity() []map[string][]string
- func (r *Route) GetStatus() int
- func (r *Route) GetSummary() string
- func (r *Route) GetTags() []string
- type RouteOption
- func WithDeprecated() RouteOption
- func WithDescription(s string) RouteOption
- func WithInternal() RouteOption
- func WithMiddleware(mw ...func(http.Handler) http.Handler) RouteOption
- func WithOperationID(id string) RouteOption
- func WithSPA() RouteOption
- func WithSecurity(security ...map[string][]string) RouteOption
- func WithSecurityName(name string) RouteOption
- func WithStatus(code int) RouteOption
- func WithSummary(s string) RouteOption
- func WithTag(tag string) RouteOption
- func WithTags(tags ...string) RouteOption
- type Router
- type SSE
- type SecurityScheme
- type Stream
- type Validator
- type Websocket
- type WebsocketHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete[In any, Out any]( r Router, pattern string, handler Handler[In, Out], opts ...RouteOption, ) error
Delete registers a new DELETE route on the router.
func Get ¶
func Get[In any, Out any]( r Router, pattern string, handler Handler[In, Out], opts ...RouteOption, ) error
Get registers a new GET route on the router.
func Options ¶
func Options[In any, Out any]( r Router, pattern string, handler Handler[In, Out], opts ...RouteOption, ) error
Options registers a new OPTIONS route on the router.
func Patch ¶
func Patch[In any, Out any]( r Router, pattern string, handler Handler[In, Out], opts ...RouteOption, ) error
Patch registers a new PATCH route on the router.
func Post ¶
func Post[In any, Out any]( r Router, pattern string, handler Handler[In, Out], opts ...RouteOption, ) error
Post registers a new POST route on the router.
func Put ¶
func Put[In any, Out any]( r Router, pattern string, handler Handler[In, Out], opts ...RouteOption, ) error
Put registers a new PUT route on the router.
func WS ¶
func WS[In any, Msg any]( r Router, pattern string, handler WebsocketHandler[In, Msg], opts ...RouteOption, ) error
WS registers a typesafe websocket route on the application or group.
Types ¶
type App ¶
type App struct {
MaxMultipartMemory int64
ShutdownTimeout time.Duration
// contains filtered or unexported fields
}
App is the core framework application, wrapping a standard library HTTP multiplexer.
func (*App) AddErrorObserver ¶
AddErrorObserver adds an error observer to the application. Error observers are called whenever an error is handled by the framework.
func (*App) AddSecurityScheme ¶
func (a *App) AddSecurityScheme(name string, scheme SecurityScheme)
AddSecurityScheme adds a security scheme to the application.
func (*App) HandleHTTP ¶
func (a *App) HandleHTTP(method, pattern string, handler http.Handler, opts ...RouteOption)
HandleHTTP registers a standard http.Handler on the application's multiplexer. This is useful for integrating third-party handlers like Prometheus or health checks that don't follow the typed Handler[In, Out] pattern. Route options such as middleware, status, tags, and security are still applied.
func (*App) Metrics ¶
func (a *App) Metrics(pattern string, handler http.Handler, opts ...RouteOption)
Metrics registers a standard http.Handler for serving metrics (e.g., Prometheus).
func (*App) OpenAPIDocument ¶
OpenAPIDocument generates an OpenAPI 3.0 document for the application.
func (*App) OpenAPIHandler ¶
OpenAPIHandler returns an http.Handler that serves the OpenAPI JSON specification.
func (*App) RedocUIHandler ¶
RedocUIHandler returns an http.Handler that serves the Redoc UI. The specURL is the URL where the OpenAPI JSON is served (e.g., "/openapi.json").
func (*App) Run ¶
Run starts the HTTP server on the given address with graceful shutdown support. It listens for SIGINT and SIGTERM signals and waits for active requests to finish up to the configured ShutdownTimeout.
func (*App) Static ¶
func (a *App) Static(prefix, root string, opts ...RouteOption)
Static registers a directory of static files to be served at the given prefix.
func (*App) StaticFS ¶
func (a *App) StaticFS(prefix string, fs http.FileSystem, opts ...RouteOption)
StaticFS registers a file system of static files to be served at the given prefix.
func (*App) SwaggerUIHandler ¶
SwaggerUIHandler returns an http.Handler that serves the Swagger UI. The specURL is the URL where the OpenAPI JSON is served (e.g., "/openapi.json").
type Binder ¶
Binder is the interface that can be implemented by types to customize how they are extracted from path, query, or header parameters.
type ContextKey ¶
type ContextKey = bind.ContextKey
ContextKey is a custom type used for context value lookups to avoid collisions with built-in string types, satisfying standard go linters (e.g., SA1029).
type ErrorHandler ¶
type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
ErrorHandler is a function that handles errors returned by handlers or the framework.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group represents a group of routes with a common prefix and middleware.
func (*Group) HandleHTTP ¶
func (g *Group) HandleHTTP(method, pattern string, handler http.Handler, opts ...RouteOption)
HandleHTTP registers a standard http.Handler on the group's prefix.
func (*Group) Metrics ¶
func (g *Group) Metrics(pattern string, handler http.Handler, opts ...RouteOption)
Metrics registers a standard http.Handler for serving metrics on the group's prefix.
func (*Group) Static ¶
func (g *Group) Static(prefix, root string, opts ...RouteOption)
func (*Group) StaticFS ¶
func (g *Group) StaticFS(prefix string, fs http.FileSystem, opts ...RouteOption)
type Option ¶
type Option func(*App)
Option configures an App instance.
func WithErrorHandler ¶
func WithErrorHandler(h ErrorHandler) Option
WithErrorHandler sets a custom error handler for the application.
func WithGlobalMiddleware ¶
WithGlobalMiddleware adds global middleware to the application.
func WithMaxMultipartMemory ¶
WithMaxMultipartMemory sets the maximum memory to use for multipart forms.
func WithShutdownTimeout ¶
WithShutdownTimeout sets the timeout for graceful shutdown.
func WithStrictHeader ¶
func WithStrictHeader() Option
WithStrictHeader enables strict mode for header parameters. If enabled, requests with unknown header parameters will return a 422 Unprocessable Entity.
func WithStrictQuery ¶
func WithStrictQuery() Option
WithStrictQuery enables strict mode for query parameters. If enabled, requests with unknown query parameters will return a 422 Unprocessable Entity.
func WithValidator ¶
WithValidator sets a custom validator for the application.
type Route ¶
type Route struct {
Method string
Pattern string
Status int
Summary string
Description string
OperationID string
Deprecated bool
Internal bool
Tags []string
Security []map[string][]string
Schema *bind.Schema
OutputType reflect.Type
// contains filtered or unexported fields
}
Route represents a registered route and its metadata.
func (*Route) GetDeprecated ¶
func (*Route) GetDescription ¶
func (*Route) GetInternal ¶
func (*Route) GetOperationID ¶
func (*Route) GetOutputType ¶
func (*Route) GetPattern ¶
func (*Route) GetSecurity ¶
func (*Route) GetSummary ¶
type RouteOption ¶
type RouteOption func(*routeMeta)
RouteOption configures a specific route at registration time.
func WithDeprecated ¶
func WithDeprecated() RouteOption
WithDeprecated marks the route as deprecated in OpenAPI.
func WithDescription ¶
func WithDescription(s string) RouteOption
WithDescription sets the description for a route.
func WithInternal ¶
func WithInternal() RouteOption
WithInternal marks the route as internal, hiding it from OpenAPI.
func WithMiddleware ¶
func WithMiddleware(mw ...func(http.Handler) http.Handler) RouteOption
WithMiddleware adds route-local middleware.
func WithOperationID ¶
func WithOperationID(id string) RouteOption
WithOperationID sets the OpenAPI operation ID for a route.
func WithSPA ¶
func WithSPA() RouteOption
WithSPA enables single-page application mode for static file serving. If enabled, 404s will fallback to index.html at the root of the static directory.
func WithSecurity ¶
func WithSecurity(security ...map[string][]string) RouteOption
WithSecurity adds OpenAPI security requirements to a route.
func WithSecurityName ¶
func WithSecurityName(name string) RouteOption
WithSecurityName adds a simple security requirement by name with no scopes.
func WithStatus ¶
func WithStatus(code int) RouteOption
WithStatus overrides the success HTTP status code for a route.
type Router ¶
type Router interface {
Handle(method, pattern string, handler http.Handler, route *Route)
HandleHTTP(method, pattern string, handler http.Handler, opts ...RouteOption)
Metrics(pattern string, handler http.Handler, opts ...RouteOption)
App() *App
Prefix() string
Middleware() []func(http.Handler) http.Handler
Static(prefix, root string, opts ...RouteOption)
StaticFS(prefix string, fs http.FileSystem, opts ...RouteOption)
WS(pattern string, handler any, opts ...RouteOption) error
}
Router is the interface implemented by App and Group for route registration.
type SecurityScheme ¶
type SecurityScheme struct {
Type string
Description string
Name string // for apiKey
In string // for apiKey: "query", "header", "cookie"
Scheme string // for http
BearerFormat string // for http ("bearer")
OpenIdConnectUrl string // for openIdConnect
}
SecurityScheme describes an authentication scheme for the API.
type Websocket ¶
type Websocket[Msg any] struct { // contains filtered or unexported fields }
Websocket is a typesafe wrapper around a websocket connection.
func (*Websocket[Msg]) Close ¶
func (ws *Websocket[Msg]) Close(code websocket.StatusCode, reason string) error
Close closes the websocket connection with the given code and reason.