Documentation
¶
Overview ¶
Package middleware contains the custom middleware used by the go-tfe SDK, as well as options for configuring the default middlewares.
Package middleware contains the custom middleware used by the go-tfe SDK.
Index ¶
- func GetForKiota(tfeSDKVersion string, options ...MiddlewareOption) ([]khttp.Middleware, error)
- func NewErrorMiddleware(errFactory APIErrorFactory) khttp.Middleware
- func NewHeadersMiddleware(headers http.Header) khttp.Middleware
- func NewRateLimitMiddleware() khttp.Middleware
- func NewRetryMiddleware(opts RetryMiddlewareOptions) khttp.Middleware
- type APIErrorFactory
- type ErrorMiddleware
- type HeadersMiddleware
- type MiddlewareOption
- type RateLimitMiddleware
- type RetryHookCallback
- type RetryMiddleware
- type RetryMiddlewareOptions
- type RetryOptions
- type ShouldRetryFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetForKiota ¶
func GetForKiota(tfeSDKVersion string, options ...MiddlewareOption) ([]khttp.Middleware, error)
GetForKiota uses the provided options to configure the default middlewares used by kiota as well as the custom middleware supplied by the SDK.
This function replaces Kiota's built-in RetryHandler with a custom RetryMiddleware. Kiota's RetryHandler has a hardcoded isRetriableErrorCode gate that only covers 429, 503, 504 and short-circuits before calling the ShouldRetry callback. Our custom middleware calls ShouldRetry unconditionally, allowing retries on 429, 425, and all 5xx (when RetryServerErrors is enabled).
func NewErrorMiddleware ¶
func NewErrorMiddleware(errFactory APIErrorFactory) khttp.Middleware
NewErrorMiddleware creates a new kiota middleware that uses the provided factory to convert HTTP responses into custom error types when the response status code indicates an error (400 or above).
func NewHeadersMiddleware ¶
func NewHeadersMiddleware(headers http.Header) khttp.Middleware
NewHeadersMiddleware creates a new instance of HeadersMiddleware with the provided headers.
func NewRateLimitMiddleware ¶
func NewRateLimitMiddleware() khttp.Middleware
NewRateLimitMiddleware creates a middleware that translates X-RateLimit-Reset headers into standard Retry-After headers for use by the retry middleware.
func NewRetryMiddleware ¶
func NewRetryMiddleware(opts RetryMiddlewareOptions) khttp.Middleware
NewRetryMiddleware creates a custom retry middleware with the given options.
Types ¶
type APIErrorFactory ¶
APIErrorFactory is a function type that takes an HTTP response and a middleware error, and returns a new error. It is used to return custom error types based on the response from the API.
type ErrorMiddleware ¶
type ErrorMiddleware struct {
// contains filtered or unexported fields
}
ErrorMiddleware is a custom middleware that uses an APIErrorFactory to convert HTTP responses into custom error types when the response status code indicates an error (400 or above).
type HeadersMiddleware ¶
type HeadersMiddleware struct {
// contains filtered or unexported fields
}
HeadersMiddleware is a custom middleware that adds the configured headers to each request.
type MiddlewareOption ¶
type MiddlewareOption struct {
// contains filtered or unexported fields
}
MiddlewareOption is a functional option for configuring the middleware pipeline.
func WithErrorInterceptorOption ¶
func WithErrorInterceptorOption(errorFactory APIErrorFactory) MiddlewareOption
WithErrorInterceptorOption creates a middleware option that configures error interception.
func WithHeaders ¶
func WithHeaders(headers nethttp.Header) MiddlewareOption
WithHeaders creates a middleware option that adds the provided headers to each request.
func WithRetryOptions ¶
func WithRetryOptions(enabled, enabledForServerErrors bool, maxRetries int, hook RetryHookCallback) MiddlewareOption
WithRetryOptions creates a middleware option that configures retry behavior.
type RateLimitMiddleware ¶
type RateLimitMiddleware struct{}
RateLimitMiddleware translates custom rate limit headers to Retry-After, which is used by the retry middleware for backoff timing.
type RetryHookCallback ¶
RetryHookCallback is called before each retry attempt with the attempt number and response.
type RetryMiddleware ¶
type RetryMiddleware struct {
// contains filtered or unexported fields
}
RetryMiddleware is a custom retry middleware that replaces Kiota's built-in RetryHandler. Unlike Kiota's implementation, it does NOT gate retries behind a hardcoded isRetriableErrorCode check (which only covers 429, 503, 504). Instead, it delegates the retry decision entirely to the provided ShouldRetry callback, allowing retries on any status code (e.g. 425, 500, 502).
type RetryMiddlewareOptions ¶
type RetryMiddlewareOptions struct {
// MaxRetries is the maximum number of retry attempts. Capped at 10.
MaxRetries int
// DelaySeconds is the base delay between retries (used for exponential backoff).
DelaySeconds int
// ShouldRetry determines whether a given response warrants a retry.
// This is called unconditionally for every non-nil response — there is no
// status code pre-filter.
ShouldRetry ShouldRetryFunc
}
RetryMiddlewareOptions configures the custom retry middleware.
type RetryOptions ¶
type RetryOptions struct {
Enabled bool
MaxRetries int
RetryServerErrors bool
Hook RetryHookCallback
}
RetryOptions configures the retry behavior for the middleware pipeline.