httpclient

package
v24.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package httpclient includes a wrapped http client for easier data access

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
}

HTTPClient is a wrapped http client for interacting with discord

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)

Get performs an http GET

func (*HTTPClient) GetBody

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

GetBody performs an http GET an returns the response body

func (*HTTPClient) GetJSON

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

GetJSON performs an http GET and unmarshals the response body into the provided target

func (*HTTPClient) Post

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

Post performs an http POST

func (*HTTPClient) PostBody

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

PostBody performs an http POST and returns the response body

func (*HTTPClient) PostJSON

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

PostJSON performs an http POST and unmarshals the response body into the provided target

func (*HTTPClient) Put

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

Put performs an http PUT

func (*HTTPClient) PutBody

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

PutBody performs an http PUT and returns the response body

func (*HTTPClient) PutJSON

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

PutJSON performs an http PUT and unmarshals the response body into the provided target

func (*HTTPClient) SetDebug

func (c *HTTPClient) SetDebug(val bool)

SetDebug turns on/off debug mode

func (*HTTPClient) SetHeaders

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

SetHeaders adds the provided headers to the set to be included in all requests

type Logger

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

Logger is the interface expected for logging

type RateLimit

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

RateLimit is a parameterized limit set that a RateLimiter uses

type RateLimiter

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

RateLimiter is a rate limiting feature that accepts outside input dynamically for limits per time

func (*RateLimiter) Report

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

Report tunes the bucket's limit

func (*RateLimiter) Wait

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

Wait waits until there is sufficient limit room to continue

Jump to

Keyboard shortcuts

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