Documentation ¶
Index ¶
- Constants
- Variables
- func E(err error) fasthttp.RequestHandler
- func H[T, O any](handle Handle[T, O]) httprouter.Handle
- func RegisterDecoder[T DecoderConstraint](contentType string, dec T, aliases ...string)
- func RegisterEncoder[T EncoderConstraint](contentType string, enc T, aliases ...string)
- type API
- func (r *API) Delete(path string, handle httprouter.Handle)
- func (r *API) Get(path string, handle httprouter.Handle)
- func (r *API) Group(path string) Router
- func (r *API) Handle(method, path string, handle httprouter.Handle)
- func (r *API) HandleFunc(method, path string, handle http.HandlerFunc)
- func (r *API) Handler(method, path string, handle http.Handler)
- func (r *API) ListenAndServe(addr string) error
- func (r *API) Patch(path string, handle httprouter.Handle)
- func (r *API) Post(path string, handle httprouter.Handle)
- func (r *API) Put(path string, handle httprouter.Handle)
- func (r *API) RequestHandler() fasthttp.RequestHandler
- func (r *API) Use(mw ...Middleware)
- type Config
- type ContextMarshaler
- type ContextUnmarshaler
- type DecoderConstraint
- type Empty
- type EncoderConstraint
- type HTTPError
- type Handle
- type Headerer
- type Marshaler
- type Middleware
- type RequestParser
- type ResponseEncoder
- type Router
- type StatusCoder
- type StatusError
- type Unmarshaler
Constants ¶
const ( ErrBadRequest = StatusError(fasthttp.StatusBadRequest) ErrForbidden = StatusError(fasthttp.StatusForbidden) ErrNotFound = StatusError(fasthttp.StatusNotFound) ErrMethodNotAllowed = StatusError(fasthttp.StatusMethodNotAllowed) ErrNotAcceptable = StatusError(fasthttp.StatusNotAcceptable) ErrUnsupportedMediaType = StatusError(fasthttp.StatusUnsupportedMediaType) ErrInternalServerError = StatusError(fasthttp.StatusInternalServerError) )
Variables ¶
var DefaultEncoding = "text/plain"
Functions ¶
func E ¶
func E(err error) fasthttp.RequestHandler
func H ¶
func H[T, O any](handle Handle[T, O]) httprouter.Handle
H wraps your handler function with the Go generics magic.
func RegisterDecoder ¶
func RegisterDecoder[T DecoderConstraint](contentType string, dec T, aliases ...string)
RegisterDecoder registers a request decoder.
func RegisterEncoder ¶
func RegisterEncoder[T EncoderConstraint](contentType string, enc T, aliases ...string)
RegisterEncoder registers a response encoder.
Types ¶
type API ¶
type API struct { NotFound fasthttp.RequestHandler MethodNotAllowed fasthttp.RequestHandler PanicHandler func(*fasthttp.RequestCtx, any) // contains filtered or unexported fields }
func (*API) Delete ¶
func (r *API) Delete(path string, handle httprouter.Handle)
Delete is a shortcut for router.Handle(http.MethodDelete, path, handle).
func (*API) Get ¶
func (r *API) Get(path string, handle httprouter.Handle)
Get is a shortcut for router.Handle(http.MethodGet, path, handle).
func (*API) Handle ¶
func (r *API) Handle(method, path string, handle httprouter.Handle)
Handle registers a new request handle with the given path and method.
func (*API) HandleFunc ¶
func (r *API) HandleFunc(method, path string, handle http.HandlerFunc)
HandlerFunc is an adapter which allows the usage of an http.HandlerFunc as a request handle.
func (*API) Handler ¶
Handler is an adapter which allows the usage of an http.Handler as a request handle.
func (*API) ListenAndServe ¶
ListenAndServe serves HTTP requests from the given TCP4 addr.
func (*API) Patch ¶
func (r *API) Patch(path string, handle httprouter.Handle)
Patch is a shortcut for router.Handle(http.MethodPatch, path, handle).
func (*API) Post ¶
func (r *API) Post(path string, handle httprouter.Handle)
Post is a shortcut for router.Handle(http.MethodPost, path, handle).
func (*API) Put ¶
func (r *API) Put(path string, handle httprouter.Handle)
Put is a shortcut for router.Handle(http.MethodPut, path, handle).
func (*API) RequestHandler ¶
func (r *API) RequestHandler() fasthttp.RequestHandler
RequestHandler creates a fasthttp.RequestHandler for the API.
func (*API) Use ¶
func (r *API) Use(mw ...Middleware)
type ContextUnmarshaler ¶
type DecoderConstraint ¶
type DecoderConstraint interface { Unmarshaler | ContextUnmarshaler | RequestParser }
type EncoderConstraint ¶
type EncoderConstraint interface { Marshaler | ContextMarshaler | ResponseEncoder }
type HTTPError ¶
type HTTPError struct {
// contains filtered or unexported fields
}
func (*HTTPError) MarshalJSON ¶
func (*HTTPError) MarshalText ¶
func (*HTTPError) MarshalXML ¶
func (*HTTPError) MarshalYAML ¶
func (*HTTPError) StatusCode ¶
type Middleware ¶
type Middleware func(fasthttp.RequestHandler) fasthttp.RequestHandler
type RequestParser ¶
type RequestParser = func(ctx *fasthttp.RequestCtx, v any) error
type ResponseEncoder ¶
type ResponseEncoder = func(ctx *fasthttp.RequestCtx, v any) error
type Router ¶
type Router interface { Get(path string, handle httprouter.Handle) Post(path string, handle httprouter.Handle) Put(path string, handle httprouter.Handle) Delete(path string, handle httprouter.Handle) Handle(method, path string, handle httprouter.Handle) Handler(method, path string, handle http.Handler) HandleFunc(method, path string, handle http.HandlerFunc) Group(path string) Router Use(mw ...Middleware) }
type StatusCoder ¶
type StatusCoder interface {
StatusCode() int
}
StatusCoder allows you to customise the HTTP response code.
type StatusError ¶
type StatusError int
StatusError creates an error from an HTTP status code.
func (StatusError) Error ¶
func (e StatusError) Error() string
func (StatusError) StatusCode ¶
func (e StatusError) StatusCode() int