Documentation
¶
Index ¶
- func Connect[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- func Delete[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- func Get[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- func Head[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- func ListenAndServe(addr string, api *API) error
- func Options[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- func Patch[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- func Post[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- func Put[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- func Trace[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
- type API
- type APIError
- type Contact
- type ExternalDocs
- type FieldError
- type HandlerFunc
- 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[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
Connect registers a CONNECT handler.
func Delete ¶
func Delete[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
Delete registers a DELETE handler.
func Get ¶
func Get[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
Get registers a GET handler.
func Head ¶
func Head[In, Resp any](api *API, path string, fn HandlerFunc[In, 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[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
Options registers an OPTIONS handler.
func Patch ¶
func Patch[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
Patch registers a PATCH handler.
func Post ¶
func Post[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
Post registers a POST handler.
func Put ¶
func Put[In, Resp any](api *API, path string, fn HandlerFunc[In, Resp], options ...RouteOption)
Put registers a PUT handler.
func Trace ¶
func Trace[In, Resp any](api *API, path string, fn HandlerFunc[In, 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 routes. The In struct's fields are discriminated by struct tags: fields with `query:"..."` tags are parsed from query parameters, and fields with `json:"..."` tags (or no query tag) are parsed from the request body. For routes without input, use struct{} as the In type.
type Info ¶
type Info struct {
Title 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