Documentation ¶
Index ¶
- Variables
- func HTTPError(err string, code int) error
- func HandleFunc(path string, metadata any, mhs ...MethodHandler)
- func WrapError(err error, code int) error
- type BypassingData
- type EmptyBody
- type HTTPErrorResponder
- type HTTPResponder
- type MethodHandler
- func Delete[I EmptyBody, M any](fn func(*Request[I, M]) error, data any) MethodHandler
- func Get[I EmptyBody, M any](fn func(*Request[I, M]) error, data any) MethodHandler
- func Head[I EmptyBody, M any](fn func(*Request[I, M]) error, data any) MethodHandler
- func Options[I EmptyBody, M any](fn func(*Request[I, M]) error, data any) MethodHandler
- func Patch[I any, M any](fn func(*Request[I, M]) error, data any) MethodHandler
- func Post[I any, M any](fn func(*Request[I, M]) error, data any) MethodHandler
- func Put[I any, M any](fn func(*Request[I, M]) error, data any) MethodHandler
- func Trace[I EmptyBody, M any](fn func(*Request[I, M]) error, data any) MethodHandler
- type Mux
- func (mux *Mux) EnableDebug(enable bool)
- func (mux *Mux) EnableDebugTimings(enable bool)
- func (mux *Mux) HandleFunc(path string, metadata any, mhs ...MethodHandler)
- func (mux *Mux) Print(w io.Writer, indent string)
- func (mux *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (mux *Mux) SetDefaultContentType(ctype string)
- type PathParser
- type Request
Constants ¶
This section is empty.
Variables ¶
var DefaultMux = &Mux{}
Functions ¶
func HTTPError ¶
HTTPError creates an error that when returned in a MethodHandler makes the server reply with the specified error message and HTTP code.
func HandleFunc ¶
func HandleFunc(path string, metadata any, mhs ...MethodHandler)
Types ¶
type BypassingData ¶
type BypassingData struct {
// contains filtered or unexported fields
}
Bypassed data can be returned directly in method handler functions.
func Bypass ¶
func Bypass(res any) BypassingData
Bypass takes any data and transforms it into data that can be directly returned in method handler functions.
func (BypassingData) Error ¶
func (wd BypassingData) Error() string
func (BypassingData) HTTPRespond ¶
func (wd BypassingData) HTTPRespond() (any, error)
type HTTPErrorResponder ¶
Returning an error that also implements HTTPErrorResponder in a MethodHandler function will cause the server to call the HTTPError method and respond with the specified int as status code and JSON-encode the 'any' value as the body.
type HTTPResponder ¶
Returning an error that also implements HTTPResponder in a MethodHandler function will cause the server to call HTTPRespond and respond to the incoming request with the returned values. If the error is non-nil the response will be an error. If the error is nil, the response will be the JSON-encoded 'any' return value.
type MethodHandler ¶
type MethodHandler struct {
// contains filtered or unexported fields
}
MethodHandlers each handles a specific HTTP Method. They are returned by the functions Delete, Get, Head, Options, Patch, Post, Put, Trace.
type Mux ¶
type Mux struct { Before func(http.ResponseWriter, *http.Request, any, any) error // contains filtered or unexported fields }
func (*Mux) EnableDebug ¶
func (*Mux) EnableDebugTimings ¶
func (*Mux) HandleFunc ¶
func (mux *Mux) HandleFunc(path string, metadata any, mhs ...MethodHandler)
HandleFunc handles requests matching the specified path in the speciified MethodHandlers. The metadata is copied for each new incoming request and can be mutated by the Mux.Before method before being available in the MethodHandler functions.
func (*Mux) SetDefaultContentType ¶
type PathParser ¶
type PathParser interface {
ParsePath()
}
type Request ¶
type Request[T any, M any] struct { Body T Metadata M Context context.Context /* Underlying native golang request / responsewriter: */ HTTPReq *http.Request ResponseWriter http.ResponseWriter }
Request stores incoming request data. Body contains the unmarshaled body of the request Metadata contains custom data that is passed to the HandleFunc and can be mutated by the mux Before Method. It also provides access to the underlying http.Request and http.ResponseWriter