Documentation ¶
Index ¶
- func Context(response http.ResponseWriter, request *http.Request) context.Context
- func Populate(rf ...gokithttp.RequestFunc) func(http.Handler) http.Handler
- func SetClient(c xhttp.Client) gokithttp.RequestFunc
- func SetContext(response http.ResponseWriter, ctx context.Context) http.ResponseWriter
- func SetErrorEncoder(ee gokithttp.ErrorEncoder) gokithttp.RequestFunc
- func WithContext(response http.ResponseWriter, request *http.Request, ctx context.Context) (http.ResponseWriter, *http.Request)
- type ContextAware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Populate ¶
Populate accepts any number of go-kit request functions and returns an Alice-style constructor that uses the request functions to build a context. The resulting context is then assocated with the request prior to the next http.Handler being invoked.
This function mimics the behavior of go-kit's transport/http package without requiring and endpoint with encoding and decoding.
func SetClient ¶
func SetClient(c xhttp.Client) gokithttp.RequestFunc
SetClient is a ContextFunc strategy that injects a supplied HTTP client into the HTTP context. Very useful when an outbound HTTP call needs to be made in response to a server request.
func SetContext ¶
func SetContext(response http.ResponseWriter, ctx context.Context) http.ResponseWriter
SetContext associates a context with a response. Useful for decorated code that needs to communicate a context back up the call stack.
Note that since ContextAware is an optional interface, it's possible that the supplied ResponseWriter does not implement ContextAware. This is tolerated, so as to be backward compatible.
The returned ResponseWriter will always be ContextAware. This writer can be used for subsequent handling code.
func SetErrorEncoder ¶
func SetErrorEncoder(ee gokithttp.ErrorEncoder) gokithttp.RequestFunc
SetErrorEncoder is a ContextFunc strategy that injects a go-kit ErrorEncoder into the HTTP request context.
func WithContext ¶
func WithContext(response http.ResponseWriter, request *http.Request, ctx context.Context) (http.ResponseWriter, *http.Request)
WithContext associates a context with the response/request pair that can later be accessed via the Context function. If response is already ContextAware, it is used and returned as is.
Useful for code that is decorating http handling code in order to establish a context.