Documentation ¶
Overview ¶
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Index ¶
- Constants
- func CoerceType(s string) interface{}
- 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 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 Auth
- type CachedOptlyMiddleware
- type ErrorResponse
- type JWTVerifier
- type JWTVerifierURL
- type NoAuth
- type OptlyMiddleware
- type Verifier
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 CoerceType ¶ added in v0.12.0
func CoerceType(s string) interface{}
CoerceType coerces typed value from string
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 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 Auth ¶ added in v0.12.0
type Auth struct {
Verifier
}
Auth is the middleware for all REST API's
func NewAuth ¶ added in v0.12.0
func NewAuth(authConfig *config.ServiceAuthConfig) *Auth
NewAuth makes Auth middleware
func (Auth) AuthorizeAPI ¶ added in v0.12.0
AuthorizeAPI is middleware for auth api
type CachedOptlyMiddleware ¶
type CachedOptlyMiddleware struct {
Cache optimizely.Cache
}
CachedOptlyMiddleware implements OptlyMiddleware backed by a cache
type JWTVerifier ¶ added in v0.12.0
type JWTVerifier struct {
// contains filtered or unexported fields
}
JWTVerifier checks token with JWT, implements Verifier
func NewJWTVerifier ¶ added in v0.12.0
func NewJWTVerifier(secretKeys []string) *JWTVerifier
NewJWTVerifier creates JWTVerifier with secret key
func (JWTVerifier) CheckToken ¶ added in v0.12.0
func (c JWTVerifier) CheckToken(token string) (*jwt.Token, error)
CheckToken checks the token and returns it if it's valid
type JWTVerifierURL ¶ added in v0.13.0
type JWTVerifierURL struct {
// contains filtered or unexported fields
}
JWTVerifierURL checks token with JWT against JWKS, implements Verifier
func NewJWTVerifierURL ¶ added in v0.13.0
func NewJWTVerifierURL(jwksURL string, updateInterval time.Duration) *JWTVerifierURL
NewJWTVerifierURL creates JWTVerifierURL with JWKS URL
func (*JWTVerifierURL) CheckToken ¶ added in v0.13.0
func (c *JWTVerifierURL) CheckToken(token string) (tk *jwt.Token, err error)
CheckToken checks the token, validates against JWKS and returns it if it's valid
type NoAuth ¶ added in v0.12.0
type NoAuth struct{}
NoAuth is NoOp for auth
func (NoAuth) CheckToken ¶ added in v0.12.0
CheckToken returns no token and no error