httpclient

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 26 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrorMapper

func DefaultErrorMapper(ctx context.Context, resp common.ResponseWrapper) error

DefaultErrorMapper returns *HttpError

func DefaultErrorRetriable

func DefaultErrorRetriable(ctx context.Context, err error) bool

func EncodeMultiSegmentPathParameter added in v0.37.0

func EncodeMultiSegmentPathParameter(p string) string

Types

type ApiClient

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

func NewApiClient

func NewApiClient(cfg ClientConfig) *ApiClient

func (*ApiClient) Do

func (c *ApiClient) Do(ctx context.Context, method, path string, opts ...DoOption) error

Do sends an HTTP request against path.

func (*ApiClient) InContextForOAuth2

func (c *ApiClient) InContextForOAuth2(ctx context.Context) context.Context

InContextForOAuth2 returns a context with a custom *http.Client to be used for only for token acquisition through golang.org/x/oauth2 package

func (*ApiClient) RoundTrip

func (c *ApiClient) RoundTrip(request *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper to integrate with golang.org/x/oauth2

type ClientConfig

type ClientConfig struct {
	AuthVisitor RequestVisitor
	Visitors    []RequestVisitor

	RetryTimeout       time.Duration
	HTTPTimeout        time.Duration
	InsecureSkipVerify bool
	DebugHeaders       bool
	DebugTruncateBytes int
	RateLimitPerSecond int

	ErrorMapper     func(ctx context.Context, resp common.ResponseWrapper) error
	ErrorRetriable  func(ctx context.Context, err error) bool
	TransientErrors []string

	Transport http.RoundTripper
}

type DoOption

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

func WithRequestData

func WithRequestData(body any) DoOption

WithRequestData takes either a struct instance, map, string, bytes, or io.Reader and sends it either as query string for GET and DELETE calls, or as request body for POST, PUT, and PATCH calls.

Experimental: this method may eventually be split into more granular options.

func WithRequestHeader

func WithRequestHeader(k, v string) DoOption

WithRequestHeader adds a request visitor, that sets a header on a request

func WithRequestHeaders

func WithRequestHeaders(headers map[string]string) DoOption

WithRequestHeaders adds a request visitor, that set all headers from a map

func WithRequestVisitor

func WithRequestVisitor(visitor func(r *http.Request) error) DoOption

WithRequestVisitor applies given function on a request

func WithResponseHeader

func WithResponseHeader(key string, value *string) DoOption

func WithResponseUnmarshal

func WithResponseUnmarshal(response any) DoOption

func WithTokenSource

func WithTokenSource(ts oauth2.TokenSource) DoOption

WithTokenSource uses the specified golang.org/x/oauth2 token source on a request

type HttpError

type HttpError struct {
	*http.Response
	Message string
	// contains filtered or unexported fields
}

func (*HttpError) Error

func (r *HttpError) Error() string

func (*HttpError) Unwrap

func (r *HttpError) Unwrap() error

type RequestVisitor

type RequestVisitor func(*http.Request) error

type TimeoutTicker added in v0.34.0

type TimeoutTicker interface {
	Tick()
	Cancel()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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