config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteNewRequest

func ExecuteNewRequest(
	ctx context.Context,
	method string,
	u string,
	body interface{},
	dst interface{},
	newError NewAPIError,
	opts ...func(*RequestConfig) error,
) error

Types

type NewAPIError

type NewAPIError func(resp *http.Response, req *http.Request) errors.APIError

type RateLimit

type RateLimit struct {
	LimitRequests     int
	LimitTokens       int
	RemainingRequests int
	RemainingTokens   int
	ResetRequests     time.Duration
	ResetTokens       time.Duration
	// contains filtered or unexported fields
}

RateLimit holds the rate limit information extracted from response headers.

func (*RateLimit) GetSnapshot

func (rl *RateLimit) GetSnapshot() RateLimit

GetSnapshot returns a copy of the current RateLimit status.

func (*RateLimit) Update

func (rl *RateLimit) Update(headers http.Header) error

Update updates the RateLimit fields based on the provided headers.

type RequestConfig

type RequestConfig struct {
	MaxRetries       int
	RequestTimeout   time.Duration
	Context          context.Context
	Request          *http.Request
	BaseURL          *url.URL
	HTTPClient       *http.Client
	Middlewares      []middleware
	APIKey           string
	APIKeyHeaderName string
	AuthToken        string
	Organization     string
	Project          string
	// If ResponseBodyInto not nil, then we will attempt to deserialize into
	// ResponseBodyInto. If Destination is a []byte, then it will return the body as
	// is.
	ResponseBodyInto interface{}
	// ResponseInto copies the \*http.Response of the corresponding request into the
	// given address
	ResponseInto **http.Response
	Body         io.Reader
	// contains filtered or unexported fields
}

RequestConfig represents all the state related to one request.

Editing the variables inside RequestConfig directly is unstable api. Prefer composing func(\*RequestConfig) error instead if possible.

func NewRequestConfig

func NewRequestConfig(
	ctx context.Context,
	method string,
	u string,
	body interface{},
	dst interface{},
	newError NewAPIError,
	opts ...func(*RequestConfig) error,
) (*RequestConfig, error)

func (*RequestConfig) Apply

func (cfg *RequestConfig) Apply(opts ...func(*RequestConfig) error) error

func (*RequestConfig) Clone

func (cfg *RequestConfig) Clone(ctx context.Context) *RequestConfig

func (*RequestConfig) Execute

func (cfg *RequestConfig) Execute() (err error)

Jump to

Keyboard shortcuts

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