Documentation
¶
Index ¶
- Constants
- func InstrRequest(op string, args ...any) (*Request, *Response, bool)
- type BaseURL
- type Client
- type ClientProvider
- type Configuration
- type DialContextFunc
- type ErrorResponse
- type ErrorResponseError
- type ForbiddenError
- type Instrumenter
- type NamedClient
- type NotFoundError
- type Option
- type Request
- type RequestFunc
- type RequestOption
- type Response
- type ResponseFunc
- type ResponseStatusCode
- type RetryIf
- type TLSConfig
- type UnauthorizedError
- type UserAgent
Constants ¶
const (
InstrumentationRequest = "http-client-request"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client interface { // WithConfiguration returns a new client with specific named configuration. WithConfiguration(name string) (Client, error) // WithContext returns a new client with specified context. WithContext(ctx context.Context) Client // WithBaseURL returns a new client with specified base URL. WithBaseURL(url string) Client // WithOptions returns a new client with additional options applied. WithOptions(opt ...Option) Client // UserAgent returns client user agent. UserAgent() string // BaseURL returns client base URL. BaseURL() string // NewRequest creates a new HTTP request. // // The returned request must be released after use by calling ReleaseRequest. NewRequest() *Request // NewResponse creates a new HTTP response. // // The returned response must be released after use by calling ReleaseResponse. NewResponse() *Response // ReleaseRequest releases the HTTP request back to pool. ReleaseRequest(req *Request) // ReleaseResponse releases the HTTP response back to pool. ReleaseResponse(resp *Response) // Do sends an HTTP request and returns an HTTP response. Do(req *Request, resp *Response) error // Get sends an HTTP GET request and returns an HTTP response body. Get(url string, opt ...RequestOption) ([]byte, error) // GetJSON sends an HTTP GET request and unmarshals the response body into v. GetJSON(url string, v any, opt ...RequestOption) error // Head sends an HTTP POST request and returns an HTTP response body. Post(url string, body []byte, opt ...RequestOption) ([]byte, error) // PostJSON sends an HTTP POST request and unmarshals response body into v. PostJSON(url string, body, v any, opt ...RequestOption) error // PostForm sends an HTTP POST request with form data and returns an HTTP response body. PostForm(url string, form map[string][]string, opt ...RequestOption) ([]byte, error) // PostMultipartForm sends an HTTP POST request with multipart form data and returns an HTTP response body. PostMultipartForm(url string, form *multipart.Form, opt ...RequestOption) ([]byte, error) // Put sends an HTTP PUT request and returns an HTTP response body. Put(url string, body []byte, opt ...RequestOption) ([]byte, error) // PutJSON sends an HTTP PUT request and unmarshals response body into v. PutJSON(url string, body, v any, opt ...RequestOption) error // Patch sends an HTTP PATCH request and returns an HTTP response body. Patch(url string, body []byte, opt ...RequestOption) ([]byte, error) // PatchJSON sends an HTTP PATCH request and unmarshals response body into v. PatchJSON(url string, body, v any, opt ...RequestOption) error // Delete sends an HTTP DELETE request. Delete(url string, opt ...RequestOption) error }
Client is the interface that provides HTTP client.
type ClientProvider ¶ added in v0.16.0
type ClientProvider interface { // HTTPClient returns HTTP client instance. HTTPClient() Client }
ClientProvider is the interface that provides HTTP client.
type Configuration ¶
type Configuration struct {
Clients map[string]NamedClient `mapstructure:"clients"`
}
Configuration represents the configuration for the HTTP client.
func (*Configuration) Validate ¶
func (c *Configuration) Validate(valid *validation.Validate) error
Validate Metrics configuration section.
type DialContextFunc ¶
DialContextFunc is a function that dials a network address.
type ErrorResponse ¶
type ErrorResponse struct {
Errors []*ErrorResponseError `json:"errors" yaml:"errors" xml:"Errors>Error"`
}
ErrorResponse represents an error response.
func (ErrorResponse) Error ¶
func (e ErrorResponse) Error() string
Error implements error interface.
type ErrorResponseError ¶
type ErrorResponseError struct { Type string `json:"type" yaml:"type" xml:"Type"` Message string `json:"message" yaml:"message" xml:"Message"` }
ErrorResponseError is an error response error details.
type ForbiddenError ¶
type ForbiddenError struct{}
ForbiddenError is an error that occurs when user access is denied.
func (ForbiddenError) Error ¶
func (ForbiddenError) Error() string
func (ForbiddenError) StatusCode ¶
func (ForbiddenError) StatusCode() int
type Instrumenter ¶
type Instrumenter instrumenter.Instrumenter
Instrumenter is a function that instruments HTTP client operations.
type NamedClient ¶
type NamedClient struct {
BaseURL string `mapstructure:"base_url" validate:"required http_url"`
}
NamedClient represents the configuration for the named client instance.
type NotFoundError ¶
type NotFoundError struct {
Resource string
}
NotFoundError is an error that occurs when searched resource is not found.
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
func (NotFoundError) StatusCode ¶
func (NotFoundError) StatusCode() int
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is a functional option for configuring the HTTP client.
type Request ¶
Request represents an HTTP request.
func (Request) SetRequestURL ¶
SetRequestURL sets the request URL.
type RequestFunc ¶
RequestFunc is a function that modifies the HTTP request.
type RequestOption ¶
type RequestOption interface {
// contains filtered or unexported methods
}
RequestOption is a functional option for configuring the HTTP request.
func WithHeader ¶
func WithHeader(key, value string) RequestOption
WithHeader sets the specified header key and value for the request.
func WithQueryArg ¶
func WithQueryArg(key string, value any, override ...bool) RequestOption
WithQueryArg sets the specified query argument key and value for the request.
type Response ¶
Response represents HTTP response.
It is forbidden copying Response instances. Create new instances and use CopyTo instead.
Response instance MUST NOT be used from concurrently running goroutines.
type ResponseFunc ¶
ResponseFunc is a function that modifies the HTTP response.
type ResponseStatusCode ¶
type ResponseStatusCode interface { // StatusCode to be set for the response. StatusCode() int }
ResponseStatusCode is an interface that error can implement to return status code that will be set for the response.
type RetryIf ¶ added in v0.18.0
type RetryIf fasthttp.RetryIfErrFunc
RetryIf is a function that determines if the request should be retried.
type UnauthorizedError ¶
type UnauthorizedError struct{}
UnauthorizedError is an error that occurs when user is not authorized.
func (UnauthorizedError) Error ¶
func (UnauthorizedError) Error() string
func (UnauthorizedError) StatusCode ¶ added in v0.15.4
func (UnauthorizedError) StatusCode() int