middleware

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package middleware //

Package middleware //

Package middleware //

Package middleware //

Package middleware //

Index

Constants

View Source
const OptlyClientKey = contextKey("optlyClient")

OptlyClientKey is the context key for the OptlyClient

View Source
const OptlyContextKey = contextKey("optlyContext")

OptlyContextKey is the context key for the OptlyContext

View Source
const OptlyRequestHeader = "X-Request-Id"

OptlyRequestHeader is the header key for the request ID

View Source
const OptlySDKHeader = "X-Optimizely-SDK-Key"

OptlySDKHeader is the header key for an ad-hoc SDK key

Variables

This section is empty.

Functions

func GetLogger

func GetLogger(r *http.Request) *zerolog.Logger

GetLogger gets the logger with some info coming from http request

func GetOptlyClient

func GetOptlyClient(r *http.Request) (*optimizely.OptlyClient, error)

GetOptlyClient is a utility to extract the OptlyClient from the http request context.

func GetOptlyContext

func GetOptlyContext(r *http.Request) (*optimizely.OptlyContext, error)

GetOptlyContext is a utility to extract the OptlyContext from the http request context.

func Metricize

func Metricize(key string) func(http.Handler) http.Handler

Metricize updates counts, total response time, and response time histogram for each URL hit, key being a combination of a method and route pattern

func RenderError

func RenderError(err error, status int, w http.ResponseWriter, r *http.Request)

RenderError sets the request status and renders the error message.

func SetRequestID

func SetRequestID(next http.Handler) http.Handler

SetRequestID sets request ID obtained from the request header itself or from newly generated id

func SetTime

func SetTime(next http.Handler) http.Handler

SetTime middleware sets the start time in request context

Types

type CachedOptlyMiddleware

type CachedOptlyMiddleware struct {
	Cache optimizely.Cache
}

CachedOptlyMiddleware implements OptlyMiddleware backed by a cache

func (*CachedOptlyMiddleware) ClientCtx

func (ctx *CachedOptlyMiddleware) ClientCtx(next http.Handler) http.Handler

ClientCtx adds a pointer to an OptlyClient to the request context. Precedence is given for any SDK key provided within the request header else the default OptlyClient will be used.

func (*CachedOptlyMiddleware) UserCtx

func (ctx *CachedOptlyMiddleware) UserCtx(next http.Handler) http.Handler

UserCtx extracts the userId and any associated attributes from the request to create an optimizely.UserContext which will be used by downstream handlers. Future iterations of this middleware would capture pulling additional detail from a UPS or attribute store.

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse Model

type Metrics

type Metrics struct {
	HitCounts             metrics.Counter
	ResponseTime          metrics.Counter
	ResponseTimeHistogram metrics.Histogram
}

Metrics struct contains url hit counts, response time and its histogram

func NewMetrics

func NewMetrics(key string) *Metrics

NewMetrics initialized metrics

type OptlyMiddleware

type OptlyMiddleware interface {
	// ClientCtx adds an OptlyClient to the request context.
	ClientCtx(next http.Handler) http.Handler
	// UserCtx adds a UserContext to the request context.
	UserCtx(next http.Handler) http.Handler
}

OptlyMiddleware encapsultes all middleware

Jump to

Keyboard shortcuts

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