Documentation ¶
Overview ¶
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Index ¶
- Constants
- func GetExperiment(r *http.Request) (*config.OptimizelyExperiment, error)
- func GetFeature(r *http.Request) (*config.OptimizelyFeature, error)
- func GetLogger(r *http.Request) *zerolog.Logger
- func GetOptlyClient(r *http.Request) (*optimizely.OptlyClient, error)
- func GetOptlyContext(r *http.Request) (*optimizely.OptlyContext, error)
- func Metricize(key string, metricsRegistry *metrics.Registry) func(http.Handler) http.Handler
- func RenderError(err error, status int, w http.ResponseWriter, r *http.Request)
- func SetRequestID(next http.Handler) http.Handler
- func SetTime(next http.Handler) http.Handler
- type CachedOptlyMiddleware
- func (mw *CachedOptlyMiddleware) ClientCtx(next http.Handler) http.Handler
- func (mw *CachedOptlyMiddleware) ExperimentCtx(next http.Handler) http.Handler
- func (mw *CachedOptlyMiddleware) FeatureCtx(next http.Handler) http.Handler
- func (mw *CachedOptlyMiddleware) UserCtx(next http.Handler) http.Handler
- type ErrorResponse
- type OptlyMiddleware
Constants ¶
const OptlyClientKey = contextKey("optlyClient")
OptlyClientKey is the context key for the OptlyClient
const OptlyContextKey = contextKey("optlyContext")
OptlyContextKey is the context key for the OptlyContext
const OptlyExperimentKey = contextKey("experimentKey")
OptlyExperimentKey is the context key used by ExperimentCtx for setting an Experiment
const OptlyFeatureKey = contextKey("featureKey")
OptlyFeatureKey is the context key used by FeatureCtx for setting a Feature
const OptlyRequestHeader = "X-Request-Id"
OptlyRequestHeader is the header key for the request ID
const OptlySDKHeader = "X-Optimizely-SDK-Key"
OptlySDKHeader is the header key for an ad-hoc SDK key
Variables ¶
This section is empty.
Functions ¶
func GetExperiment ¶ added in v0.11.0
func GetExperiment(r *http.Request) (*config.OptimizelyExperiment, error)
GetExperiment returns an OptimizelyExperiment from the request context
func GetFeature ¶ added in v0.11.0
func GetFeature(r *http.Request) (*config.OptimizelyFeature, error)
GetFeature returns an OptimizelyFeature from the request context
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 ¶
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 ¶
RenderError sets the request status and renders the error message.
func SetRequestID ¶
SetRequestID sets request ID obtained from the request header itself or from newly generated id
Types ¶
type CachedOptlyMiddleware ¶
type CachedOptlyMiddleware struct {
Cache optimizely.Cache
}
CachedOptlyMiddleware implements OptlyMiddleware backed by a cache
func (*CachedOptlyMiddleware) ClientCtx ¶
func (mw *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) ExperimentCtx ¶ added in v0.11.0
func (mw *CachedOptlyMiddleware) ExperimentCtx(next http.Handler) http.Handler
ExperimentCtx extracts the experimentKey URL param and adds a optimizelyconfig.OptimizelyExperiment to the request context. If no such experiment exists in the current config, returns 404 Note: experimentKey must be available as a URL param, and ClientCtx middleware must run prior to this middleware
func (*CachedOptlyMiddleware) FeatureCtx ¶ added in v0.11.0
func (mw *CachedOptlyMiddleware) FeatureCtx(next http.Handler) http.Handler
FeatureCtx extracts the featureKey URL param and adds an optimizelyconfig.OptimizelyFeature to the request context. If no such feature exists in the current config, returns 404 Note: featureKey must be available as a URL param, and ClientCtx middleware must run prior to this middleware
func (*CachedOptlyMiddleware) UserCtx ¶
func (mw *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 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 // FeatureCtx adds a Feature to the request context FeatureCtx(next http.Handler) http.Handler // ExperimentCtx adds an Experiment to the request context ExperimentCtx(next http.Handler) http.Handler }
OptlyMiddleware encapsultes all middleware