Documentation ¶
Overview ¶
Library convreq is a library to make HTTP requests more convenient.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithErrorHandler ¶
func ContextWithErrorHandler(ctx context.Context, f ErrorHandler) context.Context
ContextWithErrorHandler returns a new context within which all errors are rendered with ErrorHandler.
func Wrap ¶
func Wrap(f interface{}, opts ...WrapOption) http.HandlerFunc
Wrap takes a request handler function and returns a http.HandlerFunc for use with net/http. The given handler is expected to take arguments like context.Context, *http.Request and return a convreq.HttpResponse or an error.
Types ¶
type ErrorHandler ¶
type ErrorHandler = internal.ErrorHandler
ErrorHandler is a callback type that you can register with ContextWithErrorHandler or WithErrorHandler to have your own callback called to render errors.
type HttpResponse ¶
type HttpResponse = internal.HttpResponse
HttpResponse is what is to be returned from request handlers. Respond gets executed to write the response to the client.
type WrapOption ¶
type WrapOption func(wo *wrapOptions)
WrapOption can be given to Wrap to modify behavior.
func WithContextWrapper ¶
func WithContextWrapper(f func(ctx context.Context) (context.Context, func())) WrapOption
WithContextWrapper allows you to replace the context for the request. f is called just before the request gets handled, and the cancel function is called after the request is finished. The cancel function may be nil.
func WithErrorHandler ¶
func WithErrorHandler(f ErrorHandler) WrapOption
WithErrorHandler can be passed on Wrap() to set an ErrorHandler for requests.
func WithParameterType ¶
func WithParameterType(t reflect.Type, e extractor) WrapOption
WithParameterType makes Wrap() understand an extra type for request handler signatures. The extractor is a function that can derive the requested type from a ResponseWriter and Request.
func WithReturnType ¶
func WithReturnType(t reflect.Type, f interface{}) WrapOption
WithReturnType makes Wrap() understand an extra return type for request handler signatures. You should pass in a function that takes `http.ResponseWriter, *http.Request, T` where T is the type you've passed in as t.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Library genapi provides an internal API only to be used by code generated by convreq.
|
Library genapi provides an internal API only to be used by code generated by convreq. |
Library respond creates convreq.HttpResponse objects.
|
Library respond creates convreq.HttpResponse objects. |