Documentation ¶
Index ¶
- Constants
- func DrainBody(ctx context.Context, resp *http.Response)
- func LocationFromError(err error) (location string, ok bool)
- func StatusCodeFromError(err error) (statusCode int, ok bool)
- type CourseExponentialDecayReservoir
- type RefreshableURIScoringMiddleware
- type RequestRetrier
- type URIScoringMiddleware
Constants ¶
const ( StatusCodeRetryOther = http.StatusPermanentRedirect StatusCodeRetryTemporaryRedirect = http.StatusTemporaryRedirect StatusCodeThrottle = http.StatusTooManyRequests )
Variables ¶
This section is empty.
Functions ¶
func DrainBody ¶
DrainBody reads then closes a response's body if it is non-nil. This function should be deferred before a response reference is discarded.
func LocationFromError ¶ added in v2.13.0
LocationFromError retrieves the 'location' parameter from the provided werror. If the error is not a werror or does not have the location param, ok is false.
The default client error decoder sets the location parameter on its returned errors if the status code is 3xx and a location is set in the response header
func StatusCodeFromError ¶
StatusCodeFromError retrieves the 'statusCode' parameter from the provided werror. If the error is not a werror or does not have the statusCode param, ok is false.
The default client error decoder sets the statusCode parameter on its returned errors. Note that, if a custom error decoder is used, this function will only return a status code for the error if the custom decoder sets a 'statusCode' parameter on the error.
Types ¶
type CourseExponentialDecayReservoir ¶ added in v2.19.0
func NewCourseExponentialDecayReservoir ¶ added in v2.19.0
func NewCourseExponentialDecayReservoir(nanoClock func() int64, halfLife time.Duration) CourseExponentialDecayReservoir
type RefreshableURIScoringMiddleware ¶ added in v2.22.0
type RefreshableURIScoringMiddleware interface {
CurrentURIScoringMiddleware() URIScoringMiddleware
}
func NewRefreshableURIScoringMiddleware ¶ added in v2.22.0
func NewRefreshableURIScoringMiddleware(uris refreshable.StringSlice, constructor func([]string) URIScoringMiddleware) RefreshableURIScoringMiddleware
type RequestRetrier ¶ added in v2.3.0
type RequestRetrier struct {
// contains filtered or unexported fields
}
RequestRetrier manages URIs for an HTTP client, providing an API which determines whether requests should be retries and supplying the correct URL for the client to retry. In the case of servers in a service-mesh, requests will never be retried and the mesh URI will only be returned on the first call to GetNextURI
func NewRequestRetrier ¶ added in v2.3.0
func NewRequestRetrier(uris []string, retrier retry.Retrier, maxAttempts int) *RequestRetrier
NewRequestRetrier creates a new request retrier. Regardless of maxAttempts, mesh URIs will never be retried.
func (*RequestRetrier) GetNextURI ¶ added in v2.3.0
func (r *RequestRetrier) GetNextURI(resp *http.Response, respErr error) (uri string, isRelocated bool)
GetNextURI returns the next URI a client should use, or empty string if no suitable URI remaining to retry. isRelocated is true when the URI comes from a redirect's Location header. In this case, it already includes the request path.
type URIScoringMiddleware ¶ added in v2.19.0
type URIScoringMiddleware interface { GetURIsInOrderOfIncreasingScore() []string RoundTrip(req *http.Request, next http.RoundTripper) (*http.Response, error) }
func NewBalancedURIScoringMiddleware ¶ added in v2.19.0
func NewBalancedURIScoringMiddleware(uris []string, nanoClock func() int64) URIScoringMiddleware
NewBalancedURIScoringMiddleware returns URI scoring middleware that tracks in-flight requests and recent failures for each URI configured on an HTTP client. URIs are scored based on fewest in-flight requests and recent errors, where client errors are weighted the same as 1/10 of an in-flight request, server errors are weighted as 10 in-flight requests, and errors are decayed using exponential decay with a half-life of 30 seconds.
This implementation is based on Dialogue's BalancedScoreTracker: https://github.com/palantir/dialogue/blob/develop/dialogue-core/src/main/java/com/palantir/dialogue/core/BalancedScoreTracker.java
func NewRandomURIScoringMiddleware ¶ added in v2.19.0
func NewRandomURIScoringMiddleware(uris []string, nanoClock func() int64) URIScoringMiddleware
NewRandomURIScoringMiddleware returns a URI scorer that randomizes the order of URIs when scoring using a rand.Rand seeded by the nanoClock function. The middleware no-ops on each request.