requests

package
v3.1.12+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Requests

type Requests struct {
	Logger    hclog.Logger
	Client    *http.Client
	Retryable RetryableRequest
}

func New

func New(logger hclog.Logger, client *http.Client) Requests

func NewRetryableDefault

func NewRetryableDefault(logger hclog.Logger, client *http.Client) Requests

func (Requests) Do

func (opts Requests) Do(ctx context.Context, reqDef *http.Request) (resp *http.Response, logErrorWithRequest func(error) error, rerr error)

Do makes an http request. It preserves both request and response body for logging purposes. Returns logError function that logs the passed error together with request and response body for easier debugging.

func (Requests) JSON

func (opts Requests) JSON(
	reqDef *http.Request,
	res interface{}) (resp *http.Response, rerr error)

JSON makes http request and unmarshals resulting json. Returns errors on StatusCode != 200. Logs request and response body on errors.

type RetryableRequest

type RetryableRequest struct {
	MaxAttempts float64
	MaxDuration time.Duration
	RetryDelay  time.Duration
}

Jump to

Keyboard shortcuts

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