xcontext

package
v2.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2023 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(response http.ResponseWriter, request *http.Request) context.Context

func Populate

func Populate(rf ...gokithttp.RequestFunc) func(http.Handler) http.Handler

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.

Types

type ContextAware

type ContextAware interface {
	// Context *never* returns a nil context
	Context() context.Context
	SetContext(context.Context)
}

ContextAware is an optional mixin implemented by anything with can hold a context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL