Documentation
¶
Overview ¶
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Package middleware //
Index ¶
- Constants
- func AllowedHosts(allowedHosts []string) func(next http.Handler) http.Handler
- func BatchRouter(batchRequests config.BatchRequestsConfig) func(http.Handler) http.Handler
- 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 BatchOperation
- type BatchRequest
- type BatchResponse
- type CachedOptlyMiddleware
- type ErrorResponse
- type JWTVerifier
- type JWTVerifierURL
- type NoAuth
- type OptlyMiddleware
- type ResponseCollector
- 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
const OptlyUPSHeader = "X-Optimizely-UPS-Name"
OptlyUPSHeader is the header key for an ad-hoc UserProfileService name
Variables ¶
This section is empty.
Functions ¶
func AllowedHosts ¶
AllowedHosts returns a middleware function that rejects requests whose host value does not match any host in allowedHosts. Request host is determined in the following priority order: 1. X-Forwarded-Host header value 2. Forwarded header host= directive value 3. Host property of request (see Host under https://golang.org/pkg/net/http/#Request)
func BatchRouter ¶
BatchRouter intercepts requests for the given url to return a StatusOK.
func GetExperiment ¶
func GetExperiment(r *http.Request) (*config.OptimizelyExperiment, error)
GetExperiment returns an OptimizelyExperiment from the request context
func GetFeature ¶
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 ¶
type Auth struct {
Verifier
}
Auth is the middleware for all REST API's
func NewAuth ¶
func NewAuth(authConfig *config.ServiceAuthConfig) *Auth
NewAuth makes Auth middleware
func (Auth) AuthorizeAPI ¶
AuthorizeAPI is middleware for auth api
type BatchOperation ¶
type BatchOperation struct {
Method string `json:"method"`
URL string `json:"url"`
OperationID string `json:"operationID"`
Body map[string]interface{} `json:"body"`
Params map[string]string `json:"params"`
Headers map[string]string `json:"headers"`
}
BatchOperation defines a single request within a batch
type BatchRequest ¶
type BatchRequest struct {
Operations []BatchOperation `json:"operations"`
}
BatchRequest is the original request that is used for batching
type BatchResponse ¶
type BatchResponse struct {
StartedAt time.Time `json:"startedAt"`
EndedAt time.Time `json:"endedAt"`
ErrorCount int `json:"errorCount"`
ResponseItems []ResponseCollector `json:"response"`
// contains filtered or unexported fields
}
BatchResponse has the structure for the final response
func NewBatchResponse ¶
func NewBatchResponse() *BatchResponse
NewBatchResponse constructs a BatchResponse with default values
type CachedOptlyMiddleware ¶
type CachedOptlyMiddleware struct {
Cache optimizely.Cache
}
CachedOptlyMiddleware implements OptlyMiddleware backed by a cache
type JWTVerifier ¶
type JWTVerifier struct {
// contains filtered or unexported fields
}
JWTVerifier checks token with JWT, implements Verifier
func NewJWTVerifier ¶
func NewJWTVerifier(secretKeys [][]byte) *JWTVerifier
NewJWTVerifier creates JWTVerifier with secret key
func (JWTVerifier) CheckToken ¶
func (c JWTVerifier) CheckToken(token string) (*jwt.Token, error)
CheckToken checks the token and returns it if it's valid
type JWTVerifierURL ¶
type JWTVerifierURL struct {
// contains filtered or unexported fields
}
JWTVerifierURL checks token with JWT against JWKS, implements Verifier
func NewJWTVerifierURL ¶
func NewJWTVerifierURL(jwksURL string, updateInterval time.Duration) *JWTVerifierURL
NewJWTVerifierURL creates JWTVerifierURL with JWKS URL
func (*JWTVerifierURL) CheckToken ¶
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 OptlyMiddleware ¶
type OptlyMiddleware interface {
// ClientCtx adds an OptlyClient to the request context.
ClientCtx(next http.Handler) http.Handler
}
OptlyMiddleware encapsultes all middleware
type ResponseCollector ¶
type ResponseCollector struct {
Status int `json:"status"`
RequestID string `json:"requestID"`
OperationID string `json:"operationID"`
Method string `json:"method"`
URL string `json:"url"`
Body interface{} `json:"body"`
StartedAt time.Time `json:"startedAt"`
EndedAt time.Time `json:"endedAt"`
// contains filtered or unexported fields
}
ResponseCollector collects responses for the writer
func NewResponseCollector ¶
func NewResponseCollector(op BatchOperation) ResponseCollector
NewResponseCollector constructs a ResponseCollector with default values
func (*ResponseCollector) Header ¶
func (rec *ResponseCollector) Header() http.Header
Header returns header map
func (*ResponseCollector) Write ¶
func (rec *ResponseCollector) Write(b []byte) (int, error)
Write is just the collector for BatchResponse
func (*ResponseCollector) WriteHeader ¶
func (rec *ResponseCollector) WriteHeader(code int)
WriteHeader sets the status code