Example #1
0
// initClient initializes the parts common to both Client and CLIClient
func initClient(user, pass string) *Client {
	var client = &Client{LoginReq: LoginReq{user, pass}}

	client.requestor = &http.Client{
		Transport: rehttp.NewTransport(nil, // default transport
			client.retryer(MaxRetries),
			// Note: using g_timeout as upper bound for the exponential backoff.
			//       This means g_timeout has to be large enough to run MaxRetries
			//       requests with individual retries.
			rehttp.ExpJitterDelay(StepDelay, g_timeout),
		),
	}
	client.ctx, client.cancel = context.WithCancel(context.Background())

	return client
}
Example #2
0
func Example() {
	tr := rehttp.NewTransport(
		nil, // will use http.DefaultTransport
		rehttp.RetryAll(rehttp.RetryMaxRetries(3), rehttp.RetryTemporaryErr()), // max 3 retries for Temporary errors
		rehttp.ConstDelay(time.Second),                                         // wait 1s between retries
	)
	client := &http.Client{
		Transport: tr,
		Timeout:   10 * time.Second, // Client timeout applies to all retries as a whole
	}
	res, err := client.Get("http://example.com")
	if err != nil {
		// handle err
	}
	// handle response
	res.Body.Close()
}