Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NoRetry = RetryPolicy( func(req *http.Request, err error, ctx RoundTripContext) bool { return false })
NoRetry never retries. Equivalient to a nil RetryPolicy
Functions ¶
This section is empty.
Types ¶
type RetryPolicy ¶
type RetryPolicy func(req *http.Request, err error, ctx RoundTripContext) bool
RetryPolicy is a function deciding whether the request should be retried after a non-nil error from a call to the underlying RoundTripper
type RoundTripContext ¶
type RoundTripContext interface { // Target should return the URL scheme and the host for the // current backend target Target() (scheme, host string) // Retries should return the number of retries which has been made Retries() int // Exhausted should return how many times retries have led to all // relevant backend servers being tried. Exhausted() int }
RoundTripContext is an object maintained by the virtual upstream implementation which is opaque to the VirtualTransport apart from the methods specified. It should carry information enough for the VirtualUpstream to do any book keeping needed when Update() is called with the result of sending the request to the current target host.
type VirtualTransport ¶
type VirtualTransport struct { *http.Transport Upstreams map[string]VirtualUpstream RetryPolicy RetryPolicy }
VirtualTransport acts as a replacement for the stdlib http.Transport but uses a set of named VirtualUpstream implementations to do the RoundTripper functionality if the URL scheme is "vt" and will consult the provided RetryPolicy to decide whether to retry HTTP requests which fails.
type VirtualUpstream ¶
type VirtualUpstream interface { // NextTarget is called by the VirtualTransport to advance the context // to the next backend server. The first call to NextTarget will be done // with a nil context and the VirtualUpstream implemetation should return // the first context. The context will be released again with ReleaseContext() NextTarget(req *http.Request, context RoundTripContext) (RoundTripContext, error) // Update notified the VirtualUpstream of the result from sending the HTTP request // to the current Target host. Update(context RoundTripContext, err error) // ReleaseContext tells the VirtualUpstream that the context is no longer needed ReleaseContext(RoundTripContext) }
VirtualUpstream is an implementation of a logical upstream, which may consist of one or more actual backend network hosts, implementing the selection process to chose the actual host for a HTTP request.