Documentation ¶
Index ¶
- Constants
- Variables
- func AddExternalDependency(ctx context.Context, name string, dur time.Duration)
- func ClientID(next http.Handler) http.Handler
- func ContextTransfer(ctx, targetCtx context.Context) context.Context
- func ContextWithExternalDependency(ctx context.Context, edc *ExternalDependencyContext) context.Context
- func ExternalDependency(next http.Handler) http.Handler
- func GetUserAgentFromContext(ctx context.Context) (string, error)
- func GetXForwardedForHeaderFromContext(ctx context.Context) (string, error)
- func Metrics(next http.Handler) http.Handler
- func RequestInContext(next http.Handler) http.Handler
- type ExternalDependencyContext
Constants ¶
const (
ClientIDHeaderName = "Client-ID"
)
ClientIDHeaderName name of the HTTP header that is used for reporting
const ExternalDependencyHeaderName = "External-Dependencies"
ExternalDependencyHeaderName name of the HTTP header that is used for reporting
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrInvalidRequest = errors.New("request is invalid") )
All exported package errors.
var ErrEmptyAuthorizedParty = errors.New("authorized party is empty")
Functions ¶
func AddExternalDependency ¶
func ContextTransfer ¶
ContextTransfer copies a request representation from one context to another.
func ContextWithExternalDependency ¶
func ContextWithExternalDependency(ctx context.Context, edc *ExternalDependencyContext) context.Context
ContextWithExternalDependency creates a contex with the external provided dependencies
func ExternalDependency ¶
ExternalDependency middleware to report external dependencies
func GetUserAgentFromContext ¶
GetUserAgentFromContext returns the User-Agent header value from the request that is stored in the context. Returns ErrNotFound if the context does not have a request.
func GetXForwardedForHeaderFromContext ¶
GetXForwardedForHeaderFromContext returns the X-Forwarded-For header value that would express that you forwarded the request that is stored in the context.
If the remote address of the request is 12.34.56.78:9999 then the value is that remote ip without the port. If the request already includes this header, the remote ip is appended to the value of that header. For example if the request on top of the remote ip also includes the header "X-Forwarded-For: 100.100.100.100" then the resulting value is "100.100.100.100, 12.34.56.78".
Returns ErrNotFound if the context does not have a request. Returns ErrInvalidRequest if the request in the context is malformed, for example because it does not have a remote address, which should never happen.
Types ¶
type ExternalDependencyContext ¶
type ExternalDependencyContext struct {
// contains filtered or unexported fields
}
ExternalDependencyContext contains all dependencies that were seen during the request livecycle
func ExternalDependencyContextFromContext ¶
func ExternalDependencyContextFromContext(ctx context.Context) *ExternalDependencyContext
ExternalDependencyContextFromContext returns the external dependencies context or nil
func (*ExternalDependencyContext) AddDependency ¶
func (c *ExternalDependencyContext) AddDependency(name string, duration time.Duration)
func (*ExternalDependencyContext) Parse ¶
func (c *ExternalDependencyContext) Parse(s string)
Parse a external dependency value
func (*ExternalDependencyContext) String ¶
func (c *ExternalDependencyContext) String() string
String formats all external dependencies