gogetter

package module
v2.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2018 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Failer

type Failer struct {
	Getter    Getter  // Getter's Get method is invoked when the Failer instance doesn't fail.
	Frequency float64 // Frequency specifies how often a failure should occur. Set to 0.0 to never fail and 1.0 to always fail.
}

Failer is used for testing by causing periodic Get failures.

WARNING: Don't use this in production code.

func (*Failer) Get

func (f *Failer) Get(url string) (*http.Response, error)

Get periodically responds to the Get method, and periodically fails.

type Getter

type Getter interface {
	Get(url string) (*http.Response, error)
}

Getter is the interface implemented by an object that provides a Get method identical to http.Client's method, to allow composition of functionality.

func NewRoundRobin

func NewRoundRobin(getters []Getter) Getter

NewRoundRobin returns a Getter that sends successive queries to all the Getters its list.

type Prefixer

type Prefixer struct {
	// The object whose Get method is invoked to get results for a query.
	Getter Getter

	// Prefix for each query, commonly the hostname.
	Prefix string
}

Prefixer prepends the specified prefix to the URL before redirecting to the underlying Getter.

func (*Prefixer) Get

func (p *Prefixer) Get(url string) (*http.Response, error)

Get prepends the specified prefix to the URL before redirecting to the underlying Getter.

type Retrier

type Retrier struct {
	// Getter is the object whose Get method is invoked to Get the results for a query.
	Getter Getter

	// RetryCount is number of query retries to be issued if query returns error. Leave 0 to
	// never retry query errors. But if you don't want to retry errors, It's best not to use a
	// Retrier...
	RetryCount int

	// RetryCallback is predicate function that tests whether query should be retried for a
	// given error. Leave nil to retry all errors.
	RetryCallback func(error) bool

	// RetryPause is the amount of time to wait before retrying the query with the underlying
	// Getter.
	RetryPause time.Duration
}

Retrier will optionally retry queries that fail.

WARNING: Retrier *should* wrap RoundRobin. That way retries don't go to the same dead server over and over.

func (*Retrier) Get

func (r *Retrier) Get(url string) (response *http.Response, err error)

Get attempts the specified query, and optionally retries a specified number of times, based on the results of calling the RetryCallback function.

Jump to

Keyboard shortcuts

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