try

package
v1.7.28 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CITimeoutMultiplier is the multiplier for all timeout in the CI
	CITimeoutMultiplier = 3
)

Variables

This section is empty.

Functions

func Do

func Do(timeout time.Duration, operation DoCondition) error

Do repeatedly executes an operation until no error condition occurs or the given timeout is reached, whatever comes first.

func GetRequest

func GetRequest(url string, timeout time.Duration, conditions ...ResponseCondition) error

GetRequest is like Do, but runs a request against the given URL and applies the condition on the response. ResponseCondition may be nil, in which case only the request against the URL must succeed.

func Request

func Request(req *http.Request, timeout time.Duration, conditions ...ResponseCondition) error

Request is like Do, but runs a request against the given URL and applies the condition on the response. ResponseCondition may be nil, in which case only the request against the URL must succeed.

func RequestWithTransport added in v1.6.6

func RequestWithTransport(req *http.Request, timeout time.Duration, transport *http.Transport, conditions ...ResponseCondition) error

RequestWithTransport is like Do, but runs a request against the given URL and applies the condition on the response. ResponseCondition may be nil, in which case only the request against the URL must succeed.

func Response

func Response(req *http.Request, timeout time.Duration) (*http.Response, error)

Response is like Request, but returns the response for further processing at the call site. Conditions are not allowed since it would complicate signaling if the response body needs to be closed or not. Callers are expected to close on their own if the function returns a nil error.

func ResponseUntilStatusCode

func ResponseUntilStatusCode(req *http.Request, timeout time.Duration, statusCode int) (*http.Response, error)

ResponseUntilStatusCode is like Request, but returns the response for further processing at the call site. Conditions are not allowed since it would complicate signaling if the response body needs to be closed or not. Callers are expected to close on their own if the function returns a nil error.

func Sleep

func Sleep(d time.Duration)

Sleep pauses the current goroutine for at least the duration d. Deprecated: Use only when use an other Try[...] functions is not possible.

Types

type DoCondition

type DoCondition func() error

DoCondition is a retry condition function. It returns an error

func KVExists

func KVExists(kv store.Store, key string) DoCondition

KVExists is a retry condition function. Verify if a Key exists in the store

type ResponseCondition

type ResponseCondition func(*http.Response) error

ResponseCondition is a retry condition function. It receives a response, and returns an error if the response failed the condition.

func BodyContains

func BodyContains(values ...string) ResponseCondition

BodyContains returns a retry condition function. The condition returns an error if the request body does not contain all the given strings.

func BodyContainsOr

func BodyContainsOr(values ...string) ResponseCondition

BodyContainsOr returns a retry condition function. The condition returns an error if the request body does not contain one of the given strings.

func BodyNotContains added in v1.5.0

func BodyNotContains(values ...string) ResponseCondition

BodyNotContains returns a retry condition function. The condition returns an error if the request body contain one of the given strings.

func HasBody

func HasBody() ResponseCondition

HasBody returns a retry condition function. The condition returns an error if the request body does not have body content.

func HasCn added in v1.6.6

func HasCn(cn string) ResponseCondition

HasCn returns a retry condition function. The condition returns an error if the cn is not correct.

func StatusCodeIs

func StatusCodeIs(status int) ResponseCondition

StatusCodeIs returns a retry condition function. The condition returns an error if the given response's status code is not the given HTTP status code.

Jump to

Keyboard shortcuts

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