web

package
v12.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResponseMalformed = errors.New("malformed response")
	ErrRequestFailed     = errors.New("request failed")
)

Functions

func ContextGetClient

func ContextGetClient(ctx context.Context) (*resty.Client, bool)

ContextGetClient is used to retrieve a Resty client from the context.

func ContextSetClient

func ContextSetClient(ctx context.Context, client *resty.Client) context.Context

ContextSetClient is used to store a Resty client for an application in the context.

func ExecuteRequest

func ExecuteRequest(ctx context.Context, request, response any) error

ExecuteRequest performs a given request and stores the response in the given response object. If possible, the response will be automatically unmarshaled.

func NewAPIClient

func NewAPIClient(options ...Option) *resty.Client

NewAPIClient will create a new Resty client for use in an application. Options can be provided to configure the client behavior (some options can also be set per-request as per Resty documentation).

Types

type GenericResponse

type GenericResponse interface {
	Unmarshal(data []byte) error
}

GenericResponse represents a non-JSON encoded response. The UnMarshal method will be called on the response to unmarshal into the appropriate format.

type GetRequest

type GetRequest interface {
	URL() string
}

GetRequest is a HTTP GET request.

type JSONResponse

type JSONResponse interface {
	json.Unmarshaler
}

JSONResponse is a JSON encoded response. It will be automatically unmarshaled.

type Option added in v12.1.0

type Option func(*resty.Client) *resty.Client

Option represents an option that can be used to configure Resty client behavior.

func SetDefaultRetry added in v12.1.0

func SetDefaultRetry() Option

SetDefaultRetry sets up the client to retry 3 times with an exponential backoff in-between, on any request error.

func SetDefaultTimeout added in v12.1.0

func SetDefaultTimeout() Option

SetDefaultTimeout sets a default timeout for requests.

func WithInsecureConnections added in v12.1.0

func WithInsecureConnections() Option

WithInsecureConnections will tell the client to ignore TLS certificate issues.

func WithTLSConfig added in v12.1.0

func WithTLSConfig(config *tls.Config) Option

WithTLSConfig configures the client with the given tls.Config settings.

type PostRequest

type PostRequest interface {
	GetRequest
	RequestBody() json.RawMessage
}

PostRequest is a HTTP POST request with the request body provided by Body().

Jump to

Keyboard shortcuts

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