httpclient

package
v20.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrResponse = errors.New("error response")

ErrResponse is the error that is wrapped and returned when there is a non-200 api response

Functions

func NonSensitiveHeaders

func NonSensitiveHeaders(h http.Header) http.Header

NonSensitiveHeaders is a helper to strip out sensitive data from headers when logging

Types

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer is the interface for the underlying client that this package wraps around

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(deps dependencies) *HTTPClient

NewHTTPClient creates a new http client

func (*HTTPClient) Get

func (c *HTTPClient) Get(ctx context.Context, url string, headers *http.Header) (*http.Response, error)

func (*HTTPClient) GetBody

func (c *HTTPClient) GetBody(ctx context.Context, url string, headers *http.Header) (*http.Response, []byte, error)

func (*HTTPClient) GetJSON

func (c *HTTPClient) GetJSON(ctx context.Context, url string, headers *http.Header, t interface{}) (*http.Response, error)

func (*HTTPClient) Post

func (c *HTTPClient) Post(ctx context.Context, url string, headers *http.Header, body io.Reader) (*http.Response, error)

func (*HTTPClient) PostBody

func (c *HTTPClient) PostBody(ctx context.Context, url string, headers *http.Header, body io.Reader) (*http.Response, []byte, error)

func (*HTTPClient) PostJSON

func (c *HTTPClient) PostJSON(ctx context.Context, url string, headers *http.Header, body io.Reader, t interface{}) (*http.Response, error)

func (*HTTPClient) Put

func (c *HTTPClient) Put(ctx context.Context, url string, headers *http.Header, body io.Reader) (*http.Response, error)

func (*HTTPClient) PutBody

func (c *HTTPClient) PutBody(ctx context.Context, url string, headers *http.Header, body io.Reader) (*http.Response, []byte, error)

func (*HTTPClient) PutJSON

func (c *HTTPClient) PutJSON(ctx context.Context, url string, headers *http.Header, body io.Reader, t interface{}) (*http.Response, error)

func (*HTTPClient) SetDebug

func (c *HTTPClient) SetDebug(val bool)

func (*HTTPClient) SetHeaders

func (c *HTTPClient) SetHeaders(h http.Header)

type Logger

type Logger = interface {
	Log(keyvals ...interface{}) error
	Message(string, ...interface{})
	Err(string, error, ...interface{})
	Printf(string, ...interface{})
}

type RateLimit

type RateLimit struct {
	Bucket       string
	Limit        int
	LastReported time.Time
	ResetAt      time.Time
}

type RateLimiter

type RateLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*RateLimiter) Report

func (r *RateLimiter) Report(b string, limit int, reset, at time.Time)

func (*RateLimiter) Wait

func (r *RateLimiter) Wait(ctx context.Context, b string) error

Jump to

Keyboard shortcuts

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