https

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadBalancer

type LoadBalancer struct {
	// Underlying RoundTripper used to send requests.
	http.RoundTripper

	// List of hosts the requests are distributed over.
	//
	// If a request fails and its URL host is not part of
	// this list then the LoadBalancer will not retry the
	// request.
	Hosts []string

	// Timeout controls how long a host is excluded if a
	// request to this host fails. If 0, defaults to 30
	// seconds.
	Timeout time.Duration

	// Retry specifies how often the LoadBalancer retries
	// a request with different hosts bef
	Retry int
	// contains filtered or unexported fields
}

LoadBalancer is an http.RoundTripper that implements client-side load balancing.

A LoadBalancer distributes requests uniformly across a list of hosts. Clients should use the Host or URL method to construct a request to one of these hosts.

If a request to one of these hosts fails, the LoadBalancer retries the request with different hosts until either the request succeeds or there are no hosts remaining resp. the retry limit is reached. Hosts for which requests fail are temporarily excluded and no longer selected for subsequent requests.

func (*LoadBalancer) Host

func (lb *LoadBalancer) Host() (string, error)

Host returns the next host to send requests to. It prefers hosts that aren't currently suspended.

It returns an error if the list of hosts is empty but not if there are no non-suspended hosts.

func (*LoadBalancer) RoundTrip

func (lb *LoadBalancer) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes the HTTP request and returns the corresponding response on success.

If the request execution fails with a retryable error, RoundTrip retries the request with other hosts for which requests have succeeded before. It stops retrying once the request succeeds, there are no more non-suspended hosts remaining or the retry limit is reached. Hosts, for which requests fail, are temporarily excluded and no longer selected for subsequent requests or retries.

func (*LoadBalancer) URL

func (lb *LoadBalancer) URL(elems ...string) (string, string, error)

URL returns an URL string with the next host and the provided path elements joined to the existing path of base and the resulting path cleaned of any ./ or ../ elements.

The scheme of the returned URL is "https://". The second return value is the URL's host.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL