middleware

package
v0.4.22 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientIDHeaderName = "Client-ID"
)

ClientIDHeaderName name of the HTTP header that is used for reporting

View Source
const ExternalDependencyHeaderName = "External-Dependencies"

ExternalDependencyHeaderName name of the HTTP header that is used for reporting

Variables

View Source
var (
	ErrNotFound       = errors.New("not found")
	ErrInvalidRequest = errors.New("request is invalid")
)

All exported package errors.

View Source
var ErrEmptyAuthorizedParty = errors.New("authorized party is empty")

Functions

func AddExternalDependency

func AddExternalDependency(ctx context.Context, name string, dur time.Duration)

func ClientID added in v0.1.99

func ClientID(next http.Handler) http.Handler

func ContextTransfer

func ContextTransfer(ctx, targetCtx context.Context) context.Context

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

func ExternalDependency(next http.Handler) http.Handler

ExternalDependency middleware to report external dependencies

func GetUserAgentFromContext

func GetUserAgentFromContext(ctx context.Context) (string, error)

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

func GetXForwardedForHeaderFromContext(ctx context.Context) (string, error)

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.

func Metrics

func Metrics(next http.Handler) http.Handler

func RequestInContext

func RequestInContext(next http.Handler) http.Handler

RequestInContext stores a representation of the request in the context of said request. Some information of that request can then be accessed through the context using functions of this package.

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

Jump to

Keyboard shortcuts

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