http

package module
v0.0.0-...-fe5b752 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

README

Build Status codecov

failawarehttp

Go http client, with an awareness for failures

Features

  • zero/very few dependencies, plain Go
  • does sane things out of the box (meaning: exponential backoff with jitter)
  • easy code
  • drop in replacement for net/http client (not there yet, currently a subset)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrEntry

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

ErrEntry is used for logging retries and the result of retries.

type FailAwareHTTPClient

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

FailAwareHTTPClient is the extendes HTTP client. It provides the same methods as the http.Client.

func NewClient

func NewClient(options FailAwareHTTPOptions) *FailAwareHTTPClient

NewClient creates a new FFailAwareHTTP client.

func NewDefaultClient

func NewDefaultClient() *FailAwareHTTPClient

NewDefaultClient creates a FailAwareHTTP client with defaultOptions.

func (*FailAwareHTTPClient) Do

func (c *FailAwareHTTPClient) Do(originalReq *http.Request) (*http.Response, error)

Do sends an arbitrary request and retries in the case of an retrieable error

func (*FailAwareHTTPClient) Get

func (c *FailAwareHTTPClient) Get(url string) (resp *http.Response, err error)

func (*FailAwareHTTPClient) Post

func (c *FailAwareHTTPClient) Post(url, contentType string, body io.Reader) (resp *http.Response, err error)

Post does a fail-aware Post request and retries in the case of retrieable errors

type FailAwareHTTPError

type FailAwareHTTPError struct {
	Retries   int
	Errors    []ErrEntry
	LastError error
}

FailAwareHTTPError structured error returned by the FailAwareHTTP methods.

func (FailAwareHTTPError) Error

func (e FailAwareHTTPError) Error() string

type FailAwareHTTPOptions

type FailAwareHTTPOptions struct {
	MaxRetries         int
	Timeout            time.Duration
	BackOffDelayFactor time.Duration
	KeepLog            bool
	Logger             Logger
}

FailAwareHTTPOptions are the options for the FFailAwareHttp client. See NewClient(options) and ddefaultOptions.

func NewDefaultOptions

func NewDefaultOptions() FailAwareHTTPOptions

NewDefaultOptions creates new default options for the client.

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
}

Jump to

Keyboard shortcuts

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