Documentation
¶
Index ¶
- func Connect[Body, Resp any](api *API, path string, fn HandlerFuncWithBody[Body, Resp], ...)
- func Delete[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
- func Get[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
- func Head[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
- func ListenAndServe(addr string, api *API) error
- func Options[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
- func Patch[Body, Resp any](api *API, path string, fn HandlerFuncWithBody[Body, Resp], ...)
- func Post[Body, Resp any](api *API, path string, fn HandlerFuncWithBody[Body, Resp], ...)
- func Put[Body, Resp any](api *API, path string, fn HandlerFuncWithBody[Body, Resp], ...)
- func Trace[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
- type API
- type APIError
- type Contact
- type ExternalDocs
- type FieldError
- type HandlerFunc
- type HandlerFuncWithBody
- type Info
- type License
- type Option
- type RouteInfo
- type RouteOption
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
func Connect[Body, Resp any](api *API, path string, fn HandlerFuncWithBody[Body, Resp], options ...RouteOption)
Connect registers a CONNECT handler.
func Delete ¶
func Delete[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
Delete registers a DELETE handler.
func Get ¶
func Get[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
Get registers a GET handler.
func Head ¶
func Head[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
Head registers a HEAD handler.
func ListenAndServe ¶
ListenAndServe starts the HTTP server on the given address.
In production builds this is a direct call to http.ListenAndServe with zero additional overhead.
When built with -tags shiftapidev (used automatically by the Vite plugin), the following environment variables are supported:
- SHIFTAPI_EXPORT_SPEC=<path>: write the OpenAPI spec to the given file and exit without starting the server.
- SHIFTAPI_PORT=<port>: override the port in addr, allowing the Vite plugin to automatically assign a free port.
func Options ¶
func Options[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
Options registers an OPTIONS handler.
func Patch ¶
func Patch[Body, Resp any](api *API, path string, fn HandlerFuncWithBody[Body, Resp], options ...RouteOption)
Patch registers a PATCH handler.
func Post ¶
func Post[Body, Resp any](api *API, path string, fn HandlerFuncWithBody[Body, Resp], options ...RouteOption)
Post registers a POST handler.
func Put ¶
func Put[Body, Resp any](api *API, path string, fn HandlerFuncWithBody[Body, Resp], options ...RouteOption)
Put registers a PUT handler.
func Trace ¶
func Trace[Resp any](api *API, path string, fn HandlerFunc[Resp], options ...RouteOption)
Trace registers a TRACE handler.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API collects typed handler registrations, generates an OpenAPI schema, and implements http.Handler so it can be used with any standard server.
type APIError ¶
APIError is an error with an HTTP status code. Return it from handlers to control the response status code and message.
type ExternalDocs ¶
ExternalDocs links to external documentation.
type FieldError ¶
FieldError describes a single field validation failure.
type HandlerFunc ¶
HandlerFunc is a typed handler for methods without a request body (GET, DELETE, HEAD, etc.).
type HandlerFuncWithBody ¶
HandlerFuncWithBody is a typed handler for methods with a request body (POST, PUT, PATCH, etc.).
type Info ¶
type Info struct {
Title string
Summary string
Description string
TermsOfService string
Contact *Contact
License *License
Version string
}
Info describes the API.
type Option ¶
type Option func(*API)
Option configures an API.
func WithExternalDocs ¶
func WithExternalDocs(docs ExternalDocs) Option
WithExternalDocs links to external documentation.
func WithValidator ¶
WithValidator sets a custom validator instance on the API.
type RouteOption ¶
type RouteOption func(*routeConfig)
RouteOption configures a route.
func WithRouteInfo ¶
func WithRouteInfo(info RouteInfo) RouteOption
WithRouteInfo sets the route's OpenAPI metadata.
func WithStatus ¶
func WithStatus(status int) RouteOption
WithStatus sets the success HTTP status code for the route (default: 200).
type ValidationError ¶
type ValidationError struct {
Message string `json:"message"`
Errors []FieldError `json:"errors"`
}
ValidationError is returned when request body validation fails.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string