httpclient

package
v1.0.211-f82ce19 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const JSON = "application/json; charset=utf-8"

Variables

This section is empty.

Functions

func HasErrorCode

func HasErrorCode(err error, codes ...int) bool

func IsRequestProblem

func IsRequestProblem(err error) bool

Types

type Client

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

func New

func New(cfg Config) *Client

func (*Client) Call

func (c *Client) Call(ctx context.Context, r Request) (err error)

func (*Client) CloseIdleConnections

func (c *Client) CloseIdleConnections()

CloseIdleConnections is never really needed in production with our persistent clients but it is handy for testing.

type Config

type Config struct {
	Name                  string
	BaseURL               string
	AuthHeader            string
	AuthToken             string
	AcceptType            string
	Timeout               time.Duration
	MaxConnectionsPerHost int
}

type Decoder

type Decoder func(r io.Reader) error

func NewJSONDecoder

func NewJSONDecoder(resp interface{}) Decoder

NewJSONDecoder returns a decoder func enclosing the resp param the func returned takes an io reader which will be passed rto a json decoder to decode into the resp.

type HTTPError

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

func (*HTTPError) Code

func (e *HTTPError) Code() int

func (*HTTPError) Error

func (e *HTTPError) Error() string

func (*HTTPError) Is

func (e *HTTPError) Is(target error) bool

Is checks that this error is being checked for the special o11y error that is not added to the trace as an error. If the error is due to relatively expected failure response codes return true so it does not appear in the traces as an error.

type Request

type Request struct {
	Method  string
	Route   string
	Body    interface{}
	Decoder Decoder
	Cookie  *http.Cookie
	Headers map[string]string
	Timeout time.Duration
	Query   url.Values
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(method, route string, timeout time.Duration, routeParams ...interface{}) Request

NewRequest should generally be used to create a new request. This encourages the user to specify a "route" for the tracing, and avoid high cardinality routes.

Jump to

Keyboard shortcuts

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