middleware

package
v0.0.0-...-aa645ae Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package middleware //

Package middleware //

Package middleware //

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 OptlyExperimentKey = contextKey("experimentKey")

OptlyExperimentKey is the context key used by ExperimentCtx for setting an Experiment

View Source
const OptlyFeatureKey = contextKey("featureKey")

OptlyFeatureKey is the context key used by FeatureCtx for setting a Feature

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

View Source
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

func AllowedHosts(allowedHosts []string) func(next http.Handler) http.Handler

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

func BatchRouter(batchRequests config.BatchRequestsConfig) func(http.Handler) http.Handler

BatchRouter intercepts requests for the given url to return a StatusOK.

func CoerceType

func CoerceType(s string) interface{}

CoerceType coerces typed value from string

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 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 Metricize

func Metricize(key string, metricsRegistry *metrics.Registry) 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 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

func (a Auth) AuthorizeAPI(next http.Handler) http.Handler

AuthorizeAPI is middleware for auth api

func (Auth) AuthorizeAdmin

func (a Auth) AuthorizeAdmin(next http.Handler) http.Handler

AuthorizeAdmin is middleware for admin auth

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

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.

type ErrorResponse

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

ErrorResponse Model

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 NoAuth

type NoAuth struct{}

NoAuth is NoOp for auth

func (NoAuth) CheckToken

func (NoAuth) CheckToken(string) (*jwt.Token, error)

CheckToken returns no token and no error

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

type Verifier

type Verifier interface {
	CheckToken(string) (*jwt.Token, error)
}

Verifier checks token

Jump to

Keyboard shortcuts

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