retryafter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MPL-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package retryafter contains a utility function for parsing the Retry-After HTTP header.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(retryAfter string, fallback time.Duration) time.Duration

Parse parses the backoff time specified in the Retry-After header if present. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After.

The second parameter is the fallback duration to use if the header is not present or invalid.

Example:

time.Sleep(retryafter.Parse(resp.Header.Get("Retry-After"), 5*time.Second))

func Should

func Should(statusCode int, retryOnRateLimit bool) bool

Should returns true if the given status code indicates that the request should be retried.

if retryafter.Should(resp.StatusCode, true) {
	time.Sleep(retryafter.Parse(resp.Header.Get("Retry-After"), 5*time.Second))
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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