Documentation
¶
Index ¶
- type AsyncClient
- func (ac *AsyncClient) DeleteAsync(path string, options *RequestOptions) *Promise
- func (ac *AsyncClient) GetAsync(path string, options *RequestOptions) *Promise
- func (ac *AsyncClient) PatchAsync(path string, options *RequestOptions) *Promise
- func (ac *AsyncClient) PostAsync(path string, options *RequestOptions) *Promise
- func (ac *AsyncClient) PutAsync(path string, options *RequestOptions) *Promise
- func (ac *AsyncClient) SendAsync(method, path string, options *RequestOptions) *Promise
- func (ac *AsyncClient) SendConcurrent(requests []ConcurrentRequest) []ConcurrentResponse
- func (ac *AsyncClient) SendConcurrentWithLimit(requests []ConcurrentRequest, limit int) []ConcurrentResponse
- type Auth
- type BackoffStrategy
- type Client
- func (c *Client) Delete(path string, options *RequestOptions) (*Response, error)
- func (c *Client) Get(path string, options *RequestOptions) (*Response, error)
- func (c *Client) Patch(path string, options *RequestOptions) (*Response, error)
- func (c *Client) Post(path string, options *RequestOptions) (*Response, error)
- func (c *Client) Put(path string, options *RequestOptions) (*Response, error)
- func (c *Client) Request(method, path string, options *RequestOptions) (*Response, error)
- type ClientOption
- type ConcurrentRequest
- type ConcurrentResponse
- type ExponentialBackoff
- type Handler
- type HandlerStack
- type Logger
- type Middleware
- type MultipartData
- type MultipartFile
- type MultipartRequestOptions
- type Promise
- type RequestOptions
- type Response
- type SimpleLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncClient ¶
type AsyncClient struct {
*Client
}
AsyncClient extends Client with async functionality
func NewAsyncClient ¶
func NewAsyncClient(options ...ClientOption) *AsyncClient
NewAsyncClient creates a new async client
func (*AsyncClient) DeleteAsync ¶
func (ac *AsyncClient) DeleteAsync(path string, options *RequestOptions) *Promise
DeleteAsync sends an asynchronous DELETE request
func (*AsyncClient) GetAsync ¶
func (ac *AsyncClient) GetAsync(path string, options *RequestOptions) *Promise
GetAsync sends an asynchronous GET request
func (*AsyncClient) PatchAsync ¶
func (ac *AsyncClient) PatchAsync(path string, options *RequestOptions) *Promise
PatchAsync sends an asynchronous PATCH request
func (*AsyncClient) PostAsync ¶
func (ac *AsyncClient) PostAsync(path string, options *RequestOptions) *Promise
PostAsync sends an asynchronous POST request
func (*AsyncClient) PutAsync ¶
func (ac *AsyncClient) PutAsync(path string, options *RequestOptions) *Promise
PutAsync sends an asynchronous PUT request
func (*AsyncClient) SendAsync ¶
func (ac *AsyncClient) SendAsync(method, path string, options *RequestOptions) *Promise
SendAsync sends an asynchronous request
func (*AsyncClient) SendConcurrent ¶
func (ac *AsyncClient) SendConcurrent(requests []ConcurrentRequest) []ConcurrentResponse
SendConcurrent sends multiple requests concurrently
func (*AsyncClient) SendConcurrentWithLimit ¶
func (ac *AsyncClient) SendConcurrentWithLimit(requests []ConcurrentRequest, limit int) []ConcurrentResponse
SendConcurrentWithLimit sends multiple requests concurrently with a limit
type BackoffStrategy ¶
BackoffStrategy interface for retry backoff
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an HTTP client similar to Guzzle
func NewClient ¶
func NewClient(options ...ClientOption) *Client
NewClient creates a new HTTP client
func (*Client) Delete ¶
func (c *Client) Delete(path string, options *RequestOptions) (*Response, error)
Delete sends a DELETE request
func (*Client) Get ¶
func (c *Client) Get(path string, options *RequestOptions) (*Response, error)
Get sends a GET request
func (*Client) Patch ¶
func (c *Client) Patch(path string, options *RequestOptions) (*Response, error)
Patch sends a PATCH request
func (*Client) Post ¶
func (c *Client) Post(path string, options *RequestOptions) (*Response, error)
Post sends a POST request
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that configures a client
func WithAuth ¶
func WithAuth(username, password string) ClientOption
WithAuth sets authentication credentials
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL sets the base URL for the client
func WithHeaders ¶
func WithHeaders(headers map[string]string) ClientOption
WithHeaders sets default headers for all requests
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the timeout for requests
type ConcurrentRequest ¶
type ConcurrentRequest struct {
Method string
Path string
Options *RequestOptions
}
ConcurrentRequest represents a concurrent request
type ConcurrentResponse ¶
ConcurrentResponse represents a concurrent response
func WaitAll ¶
func WaitAll(promises ...*Promise) []ConcurrentResponse
WaitAll waits for all promises to complete
type ExponentialBackoff ¶
ExponentialBackoff implements exponential backoff
type HandlerStack ¶
type HandlerStack struct {
// contains filtered or unexported fields
}
HandlerStack represents a stack of middleware handlers
func NewHandlerStack ¶
func NewHandlerStack(handler Handler) *HandlerStack
NewHandlerStack creates a new handler stack
func (*HandlerStack) Next ¶
func (hs *HandlerStack) Next(req *http.Request) (*Response, error)
Next executes the next middleware in the stack
func (*HandlerStack) Push ¶
func (hs *HandlerStack) Push(middleware Middleware)
Push adds middleware to the stack
type Logger ¶
type Logger interface {
Logf(format string, args ...interface{})
}
Logger interface for logging
type Middleware ¶
Middleware represents a middleware function
func LoggingMiddleware ¶
func LoggingMiddleware(logger Logger) Middleware
LoggingMiddleware logs request and response information
func RetryMiddleware ¶
func RetryMiddleware(maxRetries int, backoff BackoffStrategy) Middleware
RetryMiddleware retries failed requests
func TimeoutMiddleware ¶
func TimeoutMiddleware(timeout time.Duration) Middleware
TimeoutMiddleware adds timeout to requests
type MultipartData ¶
type MultipartData struct {
Fields map[string]string
Files map[string]*MultipartFile
}
MultipartData represents multipart form data
func NewMultipartData ¶
func NewMultipartData() *MultipartData
NewMultipartData creates a new multipart data container
func (*MultipartData) AddField ¶
func (md *MultipartData) AddField(name, value string)
AddField adds a form field
func (*MultipartData) AddFileFromBytes ¶
func (md *MultipartData) AddFileFromBytes(fieldName, filename string, content []byte)
AddFileFromBytes adds a file from bytes
func (*MultipartData) AddFileFromPath ¶
func (md *MultipartData) AddFileFromPath(fieldName, filePath string) error
AddFileFromPath adds a file from file path
type MultipartFile ¶
MultipartFile represents a file to be uploaded
type MultipartRequestOptions ¶
type MultipartRequestOptions struct {
*RequestOptions
Multipart *MultipartData
}
MultipartRequestOptions extends RequestOptions with multipart support
func NewMultipartRequestOptions ¶
func NewMultipartRequestOptions() *MultipartRequestOptions
NewMultipartRequestOptions creates new multipart request options
func (*MultipartRequestOptions) AddField ¶
func (mro *MultipartRequestOptions) AddField(name, value string)
AddField adds a form field to multipart data
func (*MultipartRequestOptions) AddFile ¶
func (mro *MultipartRequestOptions) AddFile(fieldName, filePath string) error
AddFile adds a file to multipart data
func (*MultipartRequestOptions) AddFileFromBytes ¶
func (mro *MultipartRequestOptions) AddFileFromBytes(fieldName, filename string, content []byte)
AddFileFromBytes adds a file from bytes to multipart data
type Promise ¶
type Promise struct {
// contains filtered or unexported fields
}
Promise represents an asynchronous request result
type RequestOptions ¶
type RequestOptions struct {
Headers map[string]string
QueryParams map[string]string
FormData map[string]string
JSON interface{}
Body io.Reader
Timeout time.Duration
Auth *Auth
Cookies []*http.Cookie
AllowRedirects bool
Multipart *MultipartData
}
RequestOptions represents options for HTTP requests
type Response ¶
Response represents an HTTP response
func (*Response) GetBodyBytes ¶
GetBodyBytes returns the response body as bytes
func (*Response) GetStatusCode ¶
GetStatusCode returns the HTTP status code
func (*Response) UnmarshalJSON ¶
UnmarshalJSON unmarshals the response body as JSON
type SimpleLogger ¶
type SimpleLogger struct{}
SimpleLogger implements Logger interface
func (*SimpleLogger) Logf ¶
func (sl *SimpleLogger) Logf(format string, args ...interface{})