requesthelper

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithRetries

func WithRetries(ctx *log.Context, rm *RequestManager, sf SleepFunc, eTag string) (*http.Response, error)

WithRetries retrieves a response body using the specified downloader. Any error returned from d will be retried (and retrieved response bodies will be closed on failures). If the retries do not succeed, the last error is returned.

It sleeps in exponentially increasing durations between retries.

Types

type RequestFactory

type RequestFactory interface {
	// GetRequest returns a new GET request for the resource.
	GetRequest(ctx *log.Context, eTag string) (*http.Request, error)
}

RequestFactory describes a method to create HTTP requests.

type RequestManager

type RequestManager struct {
	// contains filtered or unexported fields
}

RequestManager provides an abstraction for http requests

func GetRequestManager

func GetRequestManager(rf RequestFactory, timeout time.Duration) *RequestManager

GetRequestManager returns a request manager for json requests

func (*RequestManager) MakeRequest

func (rm *RequestManager) MakeRequest(ctx *log.Context, eTag string) (*http.Response, error)

MakeRequest retrieves a response body and checks the response status code to see if it is 200 OK and then returns the response body. It issues a new request every time called. It is caller's responsibility to close the response body.

type SleepFunc

type SleepFunc func(d time.Duration)

SleepFunc pauses the execution for at least duration d.

var (
	// ActualSleep uses actual time to pause the execution.
	ActualSleep SleepFunc = time.Sleep
)

Jump to

Keyboard shortcuts

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