package
1.7.0
Repository: https://github.com/acronis/go-appkit.git
Documentation: pkg.go.dev

# Packages

Package throttle provides configurable middleware for throttling HTTP requests on the server side.

# Functions

DefaultInFlightLimitOnError sends HTTP response in a typical go-appkit way in case when the error occurs during the in-flight limiting.
DefaultInFlightLimitOnReject sends HTTP response in a typical go-appkit way when the in-flight limit is exceeded.
DefaultInFlightLimitOnRejectInDryRun sends HTTP response in a typical go-appkit way when the in-flight limit is exceeded in the dry-run mode.
DefaultRateLimitOnError sends HTTP response in a typical go-appkit way in case when the error occurs during the in-flight limiting.
DefaultRateLimitOnReject sends HTTP response in a typical go-appkit way when the rate limit is exceeded.
DefaultRateLimitOnRejectInDryRun sends HTTP response in a typical go-appkit way when the rate limit is exceeded in the dry-run mode.
DisableHTTPMetricsInContext disables HTTP metrics processing in the context.
GetInternalRequestIDFromContext extracts internal request id from the context.
GetLoggerFromContext extracts logger from the context.
GetLoggingParamsFromContext extracts logging params from the context.
GetRequestIDFromContext extracts external request id from the context.
GetRequestStartTimeFromContext extracts request start time from the context.
GetRetryAfterEstimatedTime returns estimated time after that the client may retry the request.
GetTraceIDFromContext extracts trace id from the context.
HTTPRequestMetrics is a middleware that collects metrics for incoming HTTP requests using Prometheus data types.
HTTPRequestMetricsWithOpts is a more configurable version of HTTPRequestMetrics middleware.
InFlightLimit is a middleware that limits the total number of currently served (in-flight) HTTP requests.
InFlightLimitWithOpts is a configurable version of a middleware to limit in-flight HTTP requests.
IsHTTPMetricsEnabledInContext checks whether HTTP metrics are enabled in the context.
Logging is a middleware that logs info about HTTP request and response.
LoggingWithOpts is a more configurable version of Logging middleware.
MustInFlightLimit is a version of InFlightLimit that panics on error.
MustInFlightLimitWithOpts is a version of InFlightLimitWithOpts that panics on error.
MustRateLimit is a version of RateLimit that panics if an error occurs.
MustRateLimitWithOpts is a version of RateLimitWithOpts that panics if an error occurs.
NewContextWithHTTPMetricsEnabled creates a new context with special flag which can toggle HTTP metrics status.
NewContextWithInternalRequestID creates a new context with internal request id.
NewContextWithLogger creates a new context with logger.
NewContextWithLoggingParams creates a new context with logging params.
NewContextWithRequestID creates a new context with external request id.
NewContextWithRequestStartTime creates a new context with request start time.
NewContextWithTraceID creates a new context with trace id.
NewHTTPRequestPrometheusMetrics creates a new instance of HTTPRequestPrometheusMetrics with default options.
NewHTTPRequestPrometheusMetricsWithOpts creates a new instance of HTTPRequestPrometheusMetrics with the provided options.
NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to hook into various parts of the response process.
RateLimit is a middleware that limits the rate of HTTP requests.
RateLimitWithOpts is a configurable version of a middleware to limit the rate of HTTP requests.
Recovery 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.
RecoveryWithOpts is a more configurable version of Recovery middleware.
RequestBodyLimit is a middleware that sets the maximum allowed size for a request body.
RequestID is a middleware that reads value of X-Request-ID request's HTTP header and generates new one if it's empty.
RequestIDWithOpts is a more configurable version of RequestID middleware.
WrapResponseWriterIfNeeded 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.

# Constants

DefaultInFlightLimitBacklogTimeout determines how long the HTTP request may be in the backlog status.
DefaultInFlightLimitMaxKeys is a default value of maximum keys number for the InFlightLimit middleware.
DefaultRateLimitBacklogTimeout determines how long the HTTP request may be in the backlog status.
DefaultRateLimitMaxKeys is a default value of maximum keys number for the RateLimit middleware.
InFlightLimitErrCode 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.
Log fields for InFlightLimit middleware.
Log fields for InFlightLimit middleware.
LoggingSecretQueryPlaceholder represents a placeholder that will be used for secret query parameters.
Supported rate-limiting algorithms.
Supported rate-limiting algorithms.
RateLimitErrCode 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.
RateLimitLogFieldKey it is the name of the logged field that contains a key for the requests rate limiter.
RecoveryDefaultStackSize defines the default size of stack part which will be logged.

# Variables

DefaultHTTPRequestDurationBuckets is default buckets into which observations of serving HTTP requests are counted.

# Structs

HTTPRequestInfoMetrics represents a request info for collecting metrics.
HTTPRequestMetricsOpts represents an options for HTTPRequestMetrics middleware.
HTTPRequestPrometheusMetrics represents collector of metrics for incoming HTTP requests.
HTTPRequestPrometheusMetricsOpts represents an options for HTTPRequestPrometheusMetrics.
InFlightLimitOpts represents an options for the middleware to limit in-flight HTTP requests.
InFlightLimitParams contains data that relates to the in-flight limiting procedure and could be used for rejecting or handling an occurred error.
LoggingOpts represents an options for Logging middleware.
LoggingParams stores parameters for the Logging middleware that may be modified dynamically by the other underlying middlewares/handlers.
Rate describes the frequency of requests.
RateLimitOpts represents an options for the RateLimit middleware.
RateLimitParams contains data that relates to the rate limiting procedure and could be used for rejecting or handling an occurred error.
RecoveryOpts represents an options for Recovery middleware.
RequestIDOpts represents an options for RequestID middleware.

# Interfaces

HTTPRequestMetricsCollector is an interface for collecting metrics for incoming HTTP requests.
WrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook into various parts of the response process.

# Type aliases

CustomLoggerProvider returns a custom logger or nil based on the request.
InFlightLimitGetKeyFunc is a function that is called for getting key for in-flight limiting.
InFlightLimitGetRetryAfterFunc is a function that is called to get a value for Retry-After response HTTP header when the in-flight limit is exceeded.
InFlightLimitOnErrorFunc is a function that is called in case of any error that may occur during the in-flight limiting.
InFlightLimitOnRejectFunc is a function that is called for rejecting HTTP request when the in-flight limit is exceeded.
RateLimitAlg represents a type for specifying rate-limiting algorithm.
RateLimitGetKeyFunc is a function that is called for getting key for rate limiting.
RateLimitGetRetryAfterFunc is a function that is called to get a value for Retry-After response HTTP header when the rate limit is exceeded.
RateLimitOnErrorFunc is a function that is called for rejecting HTTP request when the rate limit is exceeded.
RateLimitOnRejectFunc is a function that is called for rejecting HTTP request when the rate limit is exceeded.
RoutePatternGetterFunc is a function for getting route pattern from the request.
UserAgentTypeGetterFunc is a function for getting user agent type from the request.