httputil

package
v0.0.0-...-300ac43 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPClient

func NewHTTPClient() *http.Client

func WriteJSON

func WriteJSON(w http.ResponseWriter, v interface{}) error

Types

type Client

type Client struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(hclient *http.Client, opts ...ClientOption) (*Client, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, opts ...RequestOption) *Request

type ClientOption

type ClientOption func(*Client) error

func WithLogger

func WithLogger(logger *zerolog.Logger) ClientOption

type ErrorHandler

type ErrorHandler struct {
	Handler func(w http.ResponseWriter, r *http.Request) error
}

func (ErrorHandler) ServeHTTP

func (h ErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP allows our Handler type to satisfy http.Handler.

type HTTPError

type HTTPError interface {
	error
	Status() int
}

type Request

type Request struct {
	Method  string
	Url     string
	Options map[string]string
	// contains filtered or unexported fields
}

func (*Request) Body

func (r *Request) Body(value interface{}) *Request

func (*Request) Option

func (r *Request) Option(key string, value interface{}) *Request

func (*Request) Send

func (r *Request) Send(ctx context.Context) (*http.Response, error)

type RequestOption

type RequestOption func(*RequestSettings)

func WithBackoff

func WithBackoff(backoff retryablehttp.Backoff) RequestOption

func WithCheckRetry

func WithCheckRetry(checkRetry retryablehttp.CheckRetry) RequestOption

func WithRetryMax

func WithRetryMax(max int) RequestOption

func WithRetryWaitMax

func WithRetryWaitMax(d time.Duration) RequestOption

func WithRetryWaitMin

func WithRetryWaitMin(d time.Duration) RequestOption

type RequestSettings

type RequestSettings struct {
	RetryWaitMin time.Duration
	RetryWaitMax time.Duration
	RetryMax     int
	CheckRetry   retryablehttp.CheckRetry
	Backoff      retryablehttp.Backoff
}

type StatusError

type StatusError struct {
	Code int
	Err  error
}

func (StatusError) Error

func (se StatusError) Error() string

func (StatusError) Status

func (se StatusError) Status() int

Jump to

Keyboard shortcuts

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