{"modulePath":"github.com/acronis/go-appkit","version":"v1.38.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package middleware\n\nPackage middleware contains set of middlewares for HTTP server.\n\n## Constants\n\n```go\nconst (\n\tInFlightLimitLogFieldKey        = \"in_flight_limit_key\"\n\tInFlightLimitLogFieldBacklogged = \"in_flight_limit_backlogged\"\n)\n```\nLog fields for InFlightLimit middleware.\n\n```go\nconst DefaultInFlightLimitMaxKeys = 10000\n```\nDefaultInFlightLimitMaxKeys is a default value of maximum keys number for the InFlightLimit middleware.\n\n```go\nconst DefaultRateLimitBacklogTimeout = ratelimit.DefaultRateLimitBacklogTimeout\n```\nDefaultRateLimitBacklogTimeout determines how long the HTTP request may be in the backlog status.\n\n```go\nconst DefaultRateLimitMaxKeys = 10000\n```\nDefaultRateLimitMaxKeys is a default value of maximum keys number for the RateLimit middleware.\n\n```go\nconst InFlightLimitErrCode = \"tooManyInFlightRequests\"\n```\nInFlightLimitErrCode is the error code that is used in a response body if the request is rejected by the middleware that limits in-flight HTTP requests.\n\n```go\nconst (\n\t// LoggingSecretQueryPlaceholder represents a placeholder that will be used for secret query parameters.\n\tLoggingSecretQueryPlaceholder = \"_HIDDEN_\"\n)\n```\n\n```go\nconst RateLimitErrCode = \"tooManyRequests\"\n```\nRateLimitErrCode is an error code that is used in a response body if the request is rejected by the middleware that limits the rate of HTTP requests.\n\n```go\nconst RateLimitLogFieldKey = \"rate_limit_key\"\n```\nRateLimitLogFieldKey it is the name of the logged field that contains a key for the requests rate limiter.\n\n```go\nconst RecoveryDefaultStackSize = 8192\n```\nRecoveryDefaultStackSize defines the default size of stack part which will be logged.\n\n## Variables\n\n```go\nvar DefaultHTTPRequestDurationBuckets = []float64{0.01, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 150, 300, 600}\n```\nDefaultHTTPRequestDurationBuckets is default buckets into which observations of serving HTTP requests are counted.\n\n## Functions\n\n```go\nfunc DefaultInFlightLimitOnError(\n\trw http.ResponseWriter, r *http.Request, params InFlightLimitParams, err error, next http.Handler, logger log.FieldLogger,\n)\n```\nDefaultInFlightLimitOnError sends HTTP response in a typical go-appkit way in case when the error occurs during the in-flight limiting.\n\n```go\nfunc DefaultInFlightLimitOnReject(\n\trw http.ResponseWriter, r *http.Request, params InFlightLimitParams, next http.Handler, logger log.FieldLogger,\n)\n```\nDefaultInFlightLimitOnReject sends HTTP response in a typical go-appkit way when the in-flight limit is exceeded.\n\n```go\nfunc DefaultInFlightLimitOnRejectInDryRun(\n\trw http.ResponseWriter, r *http.Request, params InFlightLimitParams, next http.Handler, logger log.FieldLogger,\n)\n```\nDefaultInFlightLimitOnRejectInDryRun sends HTTP response in a typical go-appkit way when the in-flight limit is exceeded in the dry-run mode.\n\n```go\nfunc DefaultRateLimitOnError(\n\trw http.ResponseWriter, r *http.Request, params RateLimitParams, err error, next http.Handler, logger log.FieldLogger,\n)\n```\nDefaultRateLimitOnError sends HTTP response in a typical go-appkit way in case when the error occurs during the in-flight limiting.\n\n```go\nfunc DefaultRateLimitOnReject(\n\trw http.ResponseWriter, r *http.Request, params RateLimitParams, next http.Handler, logger log.FieldLogger,\n)\n```\nDefaultRateLimitOnReject sends HTTP response in a typical go-appkit way when the rate limit is exceeded, or when the request is backlogged and the backlog limit is exceeded.\n\n```go\nfunc DefaultRateLimitOnRejectInDryRun(\n\trw http.ResponseWriter, r *http.Request, params RateLimitParams, next http.Handler, logger log.FieldLogger,\n)\n```\nDefaultRateLimitOnRejectInDryRun sends HTTP response in a typical go-appkit way when the rate limit is exceeded in the dry-run mode.\n\n```go\nfunc DisableHTTPMetricsInContext(ctx context.Context)\n```\nDisableHTTPMetricsInContext disables HTTP metrics processing in the context.\n\n```go\nfunc GetInternalRequestIDFromContext(ctx context.Context) string\n```\nGetInternalRequestIDFromContext extracts internal request id from the context.\n\n```go\nfunc GetLoggerFromContext(ctx context.Context) log.FieldLogger\n```\nGetLoggerFromContext extracts logger from the context.\n\n```go\nfunc GetRequestIDFromContext(ctx context.Context) string\n```\nGetRequestIDFromContext extracts external request id from the context.\n\n```go\nfunc GetRequestStartTimeFromContext(ctx context.Context) time.Time\n```\nGetRequestStartTimeFromContext extracts request start time from the context.\n\n```go\nfunc GetRetryAfterEstimatedTime(_ *http.Request, estimatedTime time.Duration) time.Duration\n```\nGetRetryAfterEstimatedTime returns estimated time after that the client may retry the request.\n\n```go\nfunc GetTraceIDFromContext(ctx context.Context) string\n```\nGetTraceIDFromContext extracts trace id from the context.\n\n```go\nfunc HTTPRequestMetrics(\n\tcollector HTTPRequestMetricsCollector, getRoutePattern RoutePatternGetterFunc,\n) func(next http.Handler) http.Handler\n```\nHTTPRequestMetrics is a middleware that collects metrics for incoming HTTP requests using Prometheus data types.\n\n```go\nfunc HTTPRequestMetricsWithOpts(\n\tcollector HTTPRequestMetricsCollector,\n\tgetRoutePattern RoutePatternGetterFunc,\n\topts HTTPRequestMetricsOpts,\n) func(next http.Handler) http.Handler\n```\nHTTPRequestMetricsWithOpts is a more configurable version of HTTPRequestMetrics middleware.\n\n```go\nfunc InFlightLimit(limit int, errDomain string) (func(next http.Handler) http.Handler, error)\n```\nInFlightLimit is a middleware that limits the total number of currently served (in-flight) HTTP requests. It checks how many requests are in-flight and rejects with 503 if exceeded.\n\n```go\nfunc InFlightLimitWithOpts(limit int, errDomain string, opts InFlightLimitOpts) (func(next http.Handler) http.Handler, error)\n```\nInFlightLimitWithOpts is a configurable version of a middleware to limit in-flight HTTP requests.\n\n```go\nfunc IsHTTPMetricsEnabledInContext(ctx context.Context) bool\n```\nIsHTTPMetricsEnabledInContext checks whether HTTP metrics are enabled in the context.\n\n```go\nfunc Logging(logger log.FieldLogger) func(next http.Handler) http.Handler\n```\nLogging is a middleware that logs info about HTTP request and response. Also, it puts logger (with external and internal request's ids in fields) into request's context.\n\n```go\nfunc LoggingWithOpts(logger log.FieldLogger, opts LoggingOpts) func(next http.Handler) http.Handler\n```\nLoggingWithOpts is a more configurable version of Logging middleware.\n\n```go\nfunc MustInFlightLimit(limit int, errDomain string) func(next http.Handler) http.Handler\n```\nMustInFlightLimit is a version of InFlightLimit that panics on error.\n\n```go\nfunc MustInFlightLimitWithOpts(limit int, errDomain string, opts InFlightLimitOpts) func(next http.Handler) http.Handler\n```\nMustInFlightLimitWithOpts is a version of InFlightLimitWithOpts that panics on error.\n\n```go\nfunc MustRateLimit(maxRate Rate, errDomain string) func(next http.Handler) http.Handler\n```\nMustRateLimit is a version of RateLimit that panics if an error occurs.\n\n```go\nfunc MustRateLimitWithOpts(maxRate Rate, errDomain string, opts RateLimitOpts) func(next http.Handler) http.Handler\n```\nMustRateLimitWithOpts is a version of RateLimitWithOpts that panics if an error occurs.\n\n```go\nfunc NewContextWithHTTPMetricsEnabled(ctx context.Context) context.Context\n```\nNewContextWithHTTPMetricsEnabled creates a new context with special flag which can toggle HTTP metrics status.\n\n```go\nfunc NewContextWithInternalRequestID(ctx context.Context, internalRequestID string) context.Context\n```\nNewContextWithInternalRequestID creates a new context with internal request id.\n\n```go\nfunc NewContextWithLogger(ctx context.Context, logger log.FieldLogger) context.Context\n```\nNewContextWithLogger creates a new context with logger.\n\n```go\nfunc NewContextWithLoggingParams(ctx context.Context, loggingParams *LoggingParams) context.Context\n```\nNewContextWithLoggingParams creates a new context with logging params.\n\n```go\nfunc NewContextWithMetricsParams(ctx context.Context, metricsParams *MetricsParams) context.Context\n```\nNewContextWithMetricsParams creates a new context with metrics params.\n\n```go\nfunc NewContextWithRequestID(ctx context.Context, requestID string) context.Context\n```\nNewContextWithRequestID creates a new context with external request id.\n\n```go\nfunc NewContextWithRequestStartTime(ctx context.Context, startTime time.Time) context.Context\n```\nNewContextWithRequestStartTime creates a new context with request start time.\n\n```go\nfunc NewContextWithTraceID(ctx context.Context, traceID string) context.Context\n```\nNewContextWithTraceID creates a new context with trace id.\n\n```go\nfunc RateLimit(maxRate Rate, errDomain string) (func(next http.Handler) http.Handler, error)\n```\nRateLimit is a middleware that limits the rate of HTTP requests.\n\n```go\nfunc RateLimitWithOpts(maxRate Rate, errDomain string, opts RateLimitOpts) (func(next http.Handler) http.Handler, error)\n```\nRateLimitWithOpts is a configurable version of a middleware to limit the rate of HTTP requests.\n\n```go\nfunc Recovery(errDomain string) func(next http.Handler) http.Handler\n```\nRecovery is a middleware that recovers from panics, logs the panic value and a stacktrace, returns 500 HTTP status code and error in body in right format.\n\n```go\nfunc RecoveryWithOpts(errDomain string, opts RecoveryOpts) func(next http.Handler) http.Handler\n```\nRecoveryWithOpts is a more configurable version of Recovery middleware.\n\n```go\nfunc RequestBodyLimit(maxSizeBytes uint64, errDomain string) func(next http.Handler) http.Handler\n```\nRequestBodyLimit is a middleware that sets the maximum allowed size for a request body. The body limit is determined based on both Content-Length request header and actual content read. Such limiting helps to prevent the server resources being wasted if a malicious client sends a very large request body.\n\n```go\nfunc RequestID() func(next http.Handler) http.Handler\n```\nRequestID is a middleware that reads value of X-Request-ID request's HTTP header and generates new one if it's empty. Also, the middleware generates yet another id which may be used for internal purposes. The first id is named external request id, the second one - internal request id. Both these ids are put into request's context and returned in HTTP response in X-Request-ID and X-Int-Request-ID headers. It's using xid (based on Mongo Object ID algorithm). This ID generator has high performance with pretty enough entropy.\n\n```go\nfunc RequestIDWithOpts(opts RequestIDOpts) func(next http.Handler) http.Handler\n```\nRequestIDWithOpts is a more configurable version of RequestID middleware.\n\n## Types\n\n```go\ntype CustomLoggerProvider func(r *http.Request) log.FieldLogger\n```\nCustomLoggerProvider returns a custom logger or nil based on the request.\n\n```go\ntype HTTPRequestInfoMetrics struct {\n\tMethod        string\n\tRoutePattern  string\n\tUserAgentType string\n\tCustomValues  map[string]string\n}\n```\nHTTPRequestInfoMetrics represents a request info for collecting metrics.\n\n```go\ntype HTTPRequestMetricsCollector interface {\n\t// IncInFlightRequests increments the counter of in-flight requests.\n\tIncInFlightRequests(requestInfo HTTPRequestInfoMetrics)\n\n\t// DecInFlightRequests decrements the counter of in-flight requests.\n\tDecInFlightRequests(requestInfo HTTPRequestInfoMetrics)\n\n\t// ObserveRequestFinish observes the duration of the request and the status code.\n\tObserveRequestFinish(requestInfo HTTPRequestInfoMetrics, status int, startTime time.Time)\n}\n```\nHTTPRequestMetricsCollector is an interface for collecting metrics for incoming HTTP requests.\n\n```go\ntype HTTPRequestMetricsOpts struct {\n\t// Deprecated: GetUserAgentType be removed in the next major version. Please use CustomLabels with Context instead.\n\tGetUserAgentType  UserAgentTypeGetterFunc\n\tExcludedEndpoints []string\n}\n```\nHTTPRequestMetricsOpts represents an options for HTTPRequestMetrics middleware.\n\n```go\ntype HTTPRequestPrometheusMetrics struct {\n\tDurations *prometheus.HistogramVec\n\tInFlight  *prometheus.GaugeVec\n\t// contains filtered or unexported fields\n}\n```\nHTTPRequestPrometheusMetrics represents collector of metrics for incoming HTTP requests.\n\n```go\nfunc NewHTTPRequestPrometheusMetrics() *HTTPRequestPrometheusMetrics\n```\nNewHTTPRequestPrometheusMetrics creates a new instance of HTTPRequestPrometheusMetrics with default options.\n\n```go\nfunc NewHTTPRequestPrometheusMetricsWithOpts(opts HTTPRequestPrometheusMetricsOpts) *HTTPRequestPrometheusMetrics\n```\nNewHTTPRequestPrometheusMetricsWithOpts creates a new instance of HTTPRequestPrometheusMetrics with the provided options.\n\n```go\nfunc (pm *HTTPRequestPrometheusMetrics) DecInFlightRequests(requestInfo HTTPRequestInfoMetrics)\n```\nDecInFlightRequests decrements the counter of in-flight requests.\n\n```go\nfunc (pm *HTTPRequestPrometheusMetrics) IncInFlightRequests(requestInfo HTTPRequestInfoMetrics)\n```\nIncInFlightRequests increments the counter of in-flight requests.\n\n```go\nfunc (pm *HTTPRequestPrometheusMetrics) MustCurryWith(labels prometheus.Labels) *HTTPRequestPrometheusMetrics\n```\nMustCurryWith curries the metrics collector with the provided labels.\n\n```go\nfunc (pm *HTTPRequestPrometheusMetrics) MustRegister()\n```\nMustRegister does registration of metrics collector in Prometheus and panics if any error occurs.\n\n```go\nfunc (pm *HTTPRequestPrometheusMetrics) ObserveRequestFinish(\n\trequestInfo HTTPRequestInfoMetrics, status int, startTime time.Time,\n)\n```\nObserveRequestFinish observes the duration of the request and the status code.\n\n```go\nfunc (pm *HTTPRequestPrometheusMetrics) Unregister()\n```\nUnregister cancels registration of metrics collector in Prometheus.\n\n```go\ntype HTTPRequestPrometheusMetricsOpts struct {\n\t// Namespace is a namespace for metrics. It will be prepended to all metric names.\n\tNamespace string\n\n\t// DurationBuckets is a list of buckets into which observations of serving HTTP requests are counted.\n\tDurationBuckets []float64\n\n\t// ConstLabels is a set of labels that will be applied to all metrics.\n\tConstLabels prometheus.Labels\n\n\t// CurriedLabelNames is a list of label names that will be curried with the provided labels.\n\t// See HTTPRequestPrometheusMetrics.MustCurryWith method for more details.\n\t// Keep in mind that if this list is not empty,\n\t// HTTPRequestPrometheusMetrics.MustCurryWith method must be called further with the same labels.\n\t// Otherwise, the collector will panic.\n\tCurriedLabelNames []string\n\n\t// CustomLabelNames is a list of custom label names that will be added to the metrics.\n\t// Values for these labels provided via HTTPRequestInfoMetrics.CustomValues when recording metrics.\n\t// Values in HTTPRequestInfoMetrics.CustomValues can be set dynamically during request processing using MetricsParams.SetValue() method.\n\t// MetricsParams can be obtained from the context via GetMetricsParamsFromContext().\n\t// If a custom value is not set for a label name provided here, it will be recorded as an empty string in the metric.\n\t// If a custom value is set with a name not listed here, it will be ignored.\n\tCustomLabelNames []string\n}\n```\nHTTPRequestPrometheusMetricsOpts represents an options for HTTPRequestPrometheusMetrics.\n\n```go\ntype InFlightLimitGetKeyFunc func(r *http.Request) (key string, bypass bool, err error)\n```\nInFlightLimitGetKeyFunc is a function that is called for getting key for in-flight limiting.\n\n```go\ntype InFlightLimitGetRetryAfterFunc func(r *http.Request) time.Duration\n```\nInFlightLimitGetRetryAfterFunc is a function that is called to get a value for Retry-After response HTTP header when the in-flight limit is exceeded.\n\n```go\ntype InFlightLimitOnErrorFunc func(rw http.ResponseWriter, r *http.Request,\n\tparams InFlightLimitParams, err error, next http.Handler, logger log.FieldLogger)\n```\nInFlightLimitOnErrorFunc is a function that is called in case of any error that may occur during the in-flight limiting.\n\n```go\ntype InFlightLimitOnRejectFunc func(rw http.ResponseWriter, r *http.Request,\n\tparams InFlightLimitParams, next http.Handler, logger log.FieldLogger)\n```\nInFlightLimitOnRejectFunc is a function that is called for rejecting HTTP request when the in-flight limit is exceeded.\n\n```go\ntype InFlightLimitOpts struct {\n\tGetKey             InFlightLimitGetKeyFunc\n\tMaxKeys            int\n\tResponseStatusCode int\n\tGetRetryAfter      InFlightLimitGetRetryAfterFunc\n\tBacklogLimit       int\n\tBacklogTimeout     time.Duration\n\tDryRun             bool\n\n\tOnReject         InFlightLimitOnRejectFunc\n\tOnRejectInDryRun InFlightLimitOnRejectFunc\n\tOnError          InFlightLimitOnErrorFunc\n}\n```\nInFlightLimitOpts represents an options for the middleware to limit in-flight HTTP requests.\n\n```go\ntype InFlightLimitParams struct {\n\tResponseStatusCode int\n\tGetRetryAfter      InFlightLimitGetRetryAfterFunc\n\tErrDomain          string\n\tKey                string\n\tRequestBacklogged  bool\n}\n```\nInFlightLimitParams contains data that relates to the in-flight limiting procedure and could be used for rejecting or handling an occurred error.\n\n```go\ntype LoggingOpts struct {\n\tRequestStart           bool\n\tRequestHeaders         map[string]string\n\tExcludedEndpoints      []string\n\tSecretQueryParams      []string\n\tAddRequestInfoToLogger bool\n\tSlowRequestThreshold   time.Duration // controls when to include \"slow_request\" flag into final log message\n\tTimeSlotsThreshold     time.Duration // controls when to include \"time_slots\" field group into final log message\n\t// If CustomLoggerProvider is not set or returns nil, loggingHandler.logger will be used.\n\tCustomLoggerProvider CustomLoggerProvider\n}\n```\nLoggingOpts represents an options for Logging middleware.\n\n```go\ntype LoggingParams struct {\n\t// contains filtered or unexported fields\n}\n```\nLoggingParams stores parameters for the Logging middleware that may be modified dynamically by the other underlying middlewares/handlers.\n\n```go\nfunc GetLoggingParamsFromContext(ctx context.Context) *LoggingParams\n```\nGetLoggingParamsFromContext extracts logging params from the context.\n\n```go\nfunc (lp *LoggingParams) AddExcludedTimeSlotDurationInMs(name string, dur time.Duration)\n```\nAddExcludedTimeSlotDurationInMs sets (if new) or adds duration value in milliseconds to the element of the time\\_slots map. The value is also excluded from the effective request duration used by the Logging middleware, so it doesn't count towards LoggingOpts.SlowRequestThreshold and LoggingOpts.TimeSlotsThreshold. The total request duration reported in the \"duration\\_ms\" field is not affected.\n\n```go\nfunc (lp *LoggingParams) AddExcludedTimeSlotInt(name string, dur int64)\n```\nAddExcludedTimeSlotInt sets (if new) or adds duration value to the element of the time\\_slots map. The value is also excluded from the effective request duration used by the Logging middleware, so it doesn't count towards LoggingOpts.SlowRequestThreshold and LoggingOpts.TimeSlotsThreshold. The total request duration reported in the \"duration\\_ms\" field is not affected.\n\n```go\nfunc (lp *LoggingParams) AddTimeSlotDurationInMs(name string, dur time.Duration)\n```\nAddTimeSlotDurationInMs sets (if new) or adds duration value in milliseconds to the element of the time\\_slots map\n\n```go\nfunc (lp *LoggingParams) AddTimeSlotInt(name string, dur int64)\n```\nAddTimeSlotInt sets (if new) or adds duration value to the element of the time\\_slots map\n\n```go\nfunc (lp *LoggingParams) ExtendFields(fields ...log.Field)\n```\nExtendFields extends list of fields that will be logged by the Logging middleware.\n\n```go\ntype MetricsParams struct {\n\t// contains filtered or unexported fields\n}\n```\nMetricsParams stores parameters for the HTTPRequestMetrics middleware that may be modified dynamically by the other underlying middlewares/handlers.\n\n```go\nfunc GetMetricsParamsFromContext(ctx context.Context) *MetricsParams\n```\nGetMetricsParamsFromContext extracts metrics params from the context.\n\n```go\nfunc (mp *MetricsParams) SetValue(name, value string)\n```\nSetValue adds a new label with the specified name and value. If a label with the same name already exists, it will be overwritten.\n\n```go\ntype Rate = ratelimit.Rate\n```\nRate describes the frequency of requests.\n\n```go\ntype RateLimitAlg int\n```\nRateLimitAlg represents a type for specifying rate-limiting algorithm.\n\n```go\nconst (\n\tRateLimitAlgLeakyBucket RateLimitAlg = iota\n\tRateLimitAlgSlidingWindow\n)\n```\nSupported rate-limiting algorithms.\n\n```go\ntype RateLimitGetKeyFunc func(r *http.Request) (key string, bypass bool, err error)\n```\nRateLimitGetKeyFunc is a function that is called for getting key for rate limiting.\n\n```go\ntype RateLimitGetRetryAfterFunc func(r *http.Request, estimatedTime time.Duration) time.Duration\n```\nRateLimitGetRetryAfterFunc is a function that is called to get a value for Retry-After response HTTP header when the rate limit is exceeded.\n\n```go\ntype RateLimitOnErrorFunc func(\n\trw http.ResponseWriter, r *http.Request, params RateLimitParams, err error, next http.Handler, logger log.FieldLogger)\n```\nRateLimitOnErrorFunc is a function that is called for rejecting HTTP request when the rate limit is exceeded.\n\n```go\ntype RateLimitOnRejectFunc func(\n\trw http.ResponseWriter, r *http.Request, params RateLimitParams, next http.Handler, logger log.FieldLogger)\n```\nRateLimitOnRejectFunc is a function that is called for rejecting HTTP request when the rate limit is exceeded.\n\n```go\ntype RateLimitOpts struct {\n\tAlg                RateLimitAlg\n\tMaxBurst           int\n\tGetKey             RateLimitGetKeyFunc\n\tMaxKeys            int\n\tResponseStatusCode int\n\tGetRetryAfter      RateLimitGetRetryAfterFunc\n\tDryRun             bool\n\tBacklogLimit       int\n\tBacklogTimeout     time.Duration\n\n\tOnReject         RateLimitOnRejectFunc\n\tOnRejectInDryRun RateLimitOnRejectFunc\n\tOnError          RateLimitOnErrorFunc\n}\n```\nRateLimitOpts represents an options for the RateLimit middleware.\n\n```go\ntype RateLimitParams struct {\n\tErrDomain           string\n\tResponseStatusCode  int\n\tGetRetryAfter       RateLimitGetRetryAfterFunc\n\tKey                 string\n\tRequestBacklogged   bool\n\tEstimatedRetryAfter time.Duration\n}\n```\nRateLimitParams contains data that relates to the rate limiting procedure and could be used for rejecting or handling an occurred error.\n\n```go\ntype RecoveryOpts struct {\n\tStackSize int\n}\n```\nRecoveryOpts represents an options for Recovery middleware.\n\n```go\ntype RequestIDOpts struct {\n\tGenerateID         func() string\n\tGenerateInternalID func() string\n}\n```\nRequestIDOpts represents an options for RequestID middleware.\n\n```go\ntype RoutePatternGetterFunc func(r *http.Request) string\n```\nRoutePatternGetterFunc is a function for getting route pattern from the request. Used in multiple middlewares.\n\nUsually it depends on the router that is used in HTTP server:\n\n\tfunc getGorillaMuxRoutePattern(r *http.Request) string {\n\t\tcurRoute := mux.CurrentRoute(r)\n\t\tif curRoute == nil {\n\t\t\treturn \"\"\n\t\t}\n\t\tpathTemplate, err := curRoute.GetPathTemplate()\n\t\tif err != nil {\n\t\t\treturn \"\"\n\t\t}\n\t\treturn pathTemplate\n\t}\n\n\tfunc getChiRoutePattern(r *http.Request) string {\n\t\tctxVal := r.Context().Value(chi.RouteCtxKey)\n\t\tif ctxVal == nil {\n\t\t\treturn \"\"\n\t\t}\n\t\tchiCtx := ctxVal.(*chi.Context)\n\t\tif chiCtx == nil {\n\t\t\treturn \"\"\n\t\t}\n\t\treturn chiCtx.RoutePattern()\n\t}\n\n```go\ntype UserAgentTypeGetterFunc func(r *http.Request) string\n```\nUserAgentTypeGetterFunc is a function for getting user agent type from the request. The set of return values must be finite.\n\n```go\ntype WrapResponseWriter interface {\n\thttp.ResponseWriter\n\t// Status returns the HTTP status of the request, or 0 if one has not\n\t// yet been sent.\n\tStatus() int\n\t// BytesWritten returns the total number of bytes sent to the client.\n\tBytesWritten() int\n\t// ElapsedTime returns the time spent recording the response.\n\tElapsedTime() time.Duration\n\t// Tee causes the response body to be written to the given io.Writer in\n\t// addition to proxying the writes through. Only one io.Writer can be\n\t// tee'd to at once: setting a second one will overwrite the first.\n\t// Writes will be sent to the proxy before being written to this\n\t// io.Writer. It is illegal for the tee'd writer to be modified\n\t// concurrently with writes.\n\tTee(io.Writer)\n\t// Unwrap returns the original proxied target.\n\tUnwrap() http.ResponseWriter\n\t// Discard causes all writes to the original ResponseWriter be discarded,\n\t// instead writing only to the tee'd writer if it's set.\n\t// The caller is responsible for calling WriteHeader and Write on the\n\t// original ResponseWriter once the processing is done.\n\tDiscard()\n}\n```\nWrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook into various parts of the response process.\n\n```go\nfunc NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter\n```\nNewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to hook into various parts of the response process.\n\n```go\nfunc WrapResponseWriterIfNeeded(rw http.ResponseWriter, protoMajor int) WrapResponseWriter\n```\nWrapResponseWriterIfNeeded wraps an http.ResponseWriter (if it is not already wrapped), returning a proxy that allows you to hook into various parts of the response process.\n\n","path":"github.com/acronis/go-appkit/httpserver/middleware","name":"middleware","synopsis":"Package middleware contains set of middlewares for HTTP server.","isRedistributable":true}
