Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNullPointer indicates a nil receiver or nil embedded value access. ErrNullPointer = errors.New("null reference instance") // ErrInvalidRequest indicates a request construction or execution failure. ErrInvalidRequest = errors.New("invalid HTTP request") // ErrInvalidURL indicates an invalid URL input. ErrInvalidURL = errors.New("invalid URL") // ErrHTTPStatus indicates non-success HTTP status. ErrHTTPStatus = errors.New("bad HTTP status") )
Functions ¶
Types ¶
type Client ¶
type Client interface {
// Get sends a GET request.
// Deprecated: Use GetWithContext instead.
Get(u *url.URL, opts ...RequestOpts) (Response, error)
// GetWithContext sends a GET request with context.
GetWithContext(ctx context.Context, u *url.URL, opts ...RequestOpts) (Response, error)
// Post sends a POST request.
// Deprecated: Use PostWithContext instead.
Post(u *url.URL, payload io.Reader, opts ...RequestOpts) (Response, error)
// PostWithContext sends a POST request with context.
PostWithContext(ctx context.Context, u *url.URL, payload io.Reader, opts ...RequestOpts) (Response, error)
}
Client represents a fetch client.
type ClientOpts ¶
type ClientOpts func(*client)
ClientOpts configures a Client.
func WithHTTPClient ¶
func WithHTTPClient(cli *http.Client) ClientOpts
WithHTTPClient sets the HTTP client used by fetch.
If cli is nil, it falls back to a default *http.Client.
type RequestOpts ¶
RequestOpts applies options to an HTTP request.
The returned request value allows option functions to replace the request, for example when changing context with req.WithContext.
func WithContext ¶
func WithContext(ctx context.Context) RequestOpts
WithContext sets request context on an option-applied request. Deprecated: Use GetWithContext and PostWithContext instead.
func WithRequestHeaderAdd ¶
func WithRequestHeaderAdd(name, value string) RequestOpts
WithRequestHeaderAdd returns function for adding request header in http.Request.
func WithRequestHeaderSet ¶
func WithRequestHeaderSet(name, value string) RequestOpts
WithRequestHeaderSet returns function for setting request header in http.Request.
type Response ¶
type Response interface {
// Request returns the original request.
Request() *http.Request
// Header returns response headers.
Header() http.Header
// Body returns the response body reader.
Body() io.ReadCloser
// Close drains and closes the response body.
Close() error
// DumpBodyAndClose reads all body bytes and closes the response body.
DumpBodyAndClose() ([]byte, error)
}
Response wraps an HTTP response.
Click to show internal directories.
Click to hide internal directories.
