Documentation
¶
Index ¶
- func ExponentialBackoff(retry int) time.Duration
- type AsyncResult
- type BackoffFunc
- type MarshalError
- type Middleware
- type RequestBuilder
- func (rb *RequestBuilder) BodyAsBytes() ([]byte, error)
- func (rb *RequestBuilder) ReadJSONResponse(response *http.Response, target interface{}) error
- func (rb *RequestBuilder) Send() (*http.Response, error)
- func (rb *RequestBuilder) SendAndChain(chain func(*http.Response) (*RequestBuilder, error)) (*http.Response, error)
- func (rb *RequestBuilder) SendAsync() <-chan AsyncResult
- func (rb *RequestBuilder) Use(middleware Middleware) *RequestBuilder
- func (rb *RequestBuilder) WithClient(client *http.Client) *RequestBuilder
- func (rb *RequestBuilder) WithCustomBody(body io.Reader) *RequestBuilder
- func (rb *RequestBuilder) WithFile(fieldName, filePath string) (*RequestBuilder, error)
- func (rb *RequestBuilder) WithHeader(key, value string) *RequestBuilder
- func (rb *RequestBuilder) WithJSONBody(data interface{}) (*RequestBuilder, error)
- func (rb *RequestBuilder) WithRateLimiter(rps int, burst int) *RequestBuilder
- func (rb *RequestBuilder) WithRetry(retries int, backoff BackoffFunc) *RequestBuilder
- func (rb *RequestBuilder) WithTimeout(timeout time.Duration) *RequestBuilder
- type RequestError
- type UnmarshalError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExponentialBackoff ¶
ExponentialBackoff calculates the backoff duration for retries using exponential backoff strategy
Types ¶
type AsyncResult ¶
AsyncResult is the result of an asynchronous request
type BackoffFunc ¶
BackoffFunc is a function that is used to calculate the backoff duration between retries
type MarshalError ¶
type MarshalError struct {
Err error
}
MarshalError is returned when there is an error marshaling the request body
type Middleware ¶
Middleware is a function that is executed on the response before returning it to the caller
type RequestBuilder ¶
type RequestBuilder struct {
// contains filtered or unexported fields
}
RequestBuilder is used to build a request. Always use NewRequestBuilder to create a new instance
func NewRequestBuilder ¶
func NewRequestBuilder(method, url string) *RequestBuilder
NewRequestBuilder creates a new request builder
func (*RequestBuilder) BodyAsBytes ¶
func (rb *RequestBuilder) BodyAsBytes() ([]byte, error)
BodyAsBytes returns the request body as a byte array
func (*RequestBuilder) ReadJSONResponse ¶
func (rb *RequestBuilder) ReadJSONResponse(response *http.Response, target interface{}) error
ReadJSONResponse reads the response body and unmarshals it into the target object
func (*RequestBuilder) Send ¶
func (rb *RequestBuilder) Send() (*http.Response, error)
Send sends the request and returns the response
func (*RequestBuilder) SendAndChain ¶
func (rb *RequestBuilder) SendAndChain(chain func(*http.Response) (*RequestBuilder, error)) (*http.Response, error)
SendAndChain sends the request and returns the response
func (*RequestBuilder) SendAsync ¶
func (rb *RequestBuilder) SendAsync() <-chan AsyncResult
SendAsync sends the request asynchronously and returns a channel that will contain the response
func (*RequestBuilder) Use ¶
func (rb *RequestBuilder) Use(middleware Middleware) *RequestBuilder
Use Add a function to register middleware
func (*RequestBuilder) WithClient ¶
func (rb *RequestBuilder) WithClient(client *http.Client) *RequestBuilder
WithClient sets the http client to use for the request
func (*RequestBuilder) WithCustomBody ¶
func (rb *RequestBuilder) WithCustomBody(body io.Reader) *RequestBuilder
WithCustomBody adds a custom body to the request
func (*RequestBuilder) WithFile ¶
func (rb *RequestBuilder) WithFile(fieldName, filePath string) (*RequestBuilder, error)
WithFile adds a file to the request as a multipart form data
func (*RequestBuilder) WithHeader ¶
func (rb *RequestBuilder) WithHeader(key, value string) *RequestBuilder
WithHeader adds a header to the request
func (*RequestBuilder) WithJSONBody ¶
func (rb *RequestBuilder) WithJSONBody(data interface{}) (*RequestBuilder, error)
WithJSONBody adds a JSON body to the request
func (*RequestBuilder) WithRateLimiter ¶
func (rb *RequestBuilder) WithRateLimiter(rps int, burst int) *RequestBuilder
WithRateLimiter sets the rate limiter for the request
func (*RequestBuilder) WithRetry ¶
func (rb *RequestBuilder) WithRetry(retries int, backoff BackoffFunc) *RequestBuilder
WithRetry sets the number of retries and the backoff function for the request
func (*RequestBuilder) WithTimeout ¶
func (rb *RequestBuilder) WithTimeout(timeout time.Duration) *RequestBuilder
WithTimeout sets the timeout for the request
type RequestError ¶
type RequestError struct {
Err error
}
RequestError returned when there is an error making the request
type UnmarshalError ¶
type UnmarshalError struct {
Err error
}
UnmarshalError is returned when there is an error unmarshaling the response body
func (*UnmarshalError) Error ¶
func (e *UnmarshalError) Error() string
Error returns the error message