Documentation
¶
Index ¶
- func NewDefaultHTTPClient() (*http.Client, error)
- type Blackbox
- type Client
- type ClientOption
- type ClientOptions
- type DefaultTool
- func (d *DefaultTool) CopyHeaders(ctx context.Context, dst, src *http.Request, headers ...string) error
- func (d *DefaultTool) DecodeBody(ctx context.Context, r *http.Request, v any) error
- func (d *DefaultTool) Do(ctx context.Context, r *http.Request) (*http.Response, error)
- func (d *DefaultTool) DoWithTimeout(ctx context.Context, r *http.Request, t time.Duration) (*http.Response, error)
- func (d *DefaultTool) GetHeaders(ctx context.Context, r *http.Request) (http.Header, error)
- func (d *DefaultTool) NewRequest(ctx context.Context, method, url string, opts contract.RequestOptions) (*http.Request, error)
- func (d *DefaultTool) OpenFile(ctx context.Context, fsys http.FileSystem, name string) (http.File, error)
- func (d *DefaultTool) ParseForm(ctx context.Context, r *http.Request) error
- func (d *DefaultTool) QueryString(ctx context.Context, pairs ...string) (string, error)
- func (d *DefaultTool) RespondJSON(ctx context.Context, w http.ResponseWriter, v any, status int, escapeHTML bool) error
- func (d *DefaultTool) ServeContent(ctx context.Context, opts contract.ServeContentOptions) error
- func (d *DefaultTool) ServeFile(ctx context.Context, opts contract.ServeFileOptions) error
- func (d *DefaultTool) ServeHTML(ctx context.Context, w http.ResponseWriter, body io.Reader, status int) error
- func (d *DefaultTool) SetQueryParams(ctx context.Context, r *http.Request, q map[string][]string, override bool) error
- func (d *DefaultTool) ValidateQueryParams(ctx context.Context, q map[string][]string, rules ...contract.QueryParamRule) error
- func (d *DefaultTool) Write(ctx context.Context, w http.ResponseWriter, b []byte) (int, error)
- type Dependencies
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDefaultHTTPClient ¶ added in v0.1.559
NewDefaultHTTPClient returns a properly configured *http.Client with permissive timeouts for large file uploads and long-lived connections (e.g., WebSocket handshakes). Timeouts are controlled by the provided context in the calling code.
Types ¶
type Blackbox ¶
type Blackbox interface {
contract.HTTPRequester
contract.HTTPWriter
contract.HTTPFileOpener
contract.HTTPFormParser
}
type Client ¶
type Client interface {
Blackbox
contract.HTTPOperator
}
func NewClient ¶
func NewClient(d Dependencies, opts ClientOptions) (Client, error)
type ClientOption ¶ added in v0.1.14
type ClientOption = contract.Opt[ClientOptions]
func WithServeFileFS ¶ added in v0.1.896
func WithServeFileFS(x fs.FS) ClientOption
func WithTimeout ¶ added in v0.1.14
func WithTimeout(x time.Duration) ClientOption
type ClientOptions ¶ added in v0.1.14
func ApplyClientOptions ¶ added in v0.1.14
func ApplyClientOptions(opts *ClientOptions, modifiers ...ClientOption) ClientOptions
type DefaultTool ¶ added in v0.1.11
func NewTool ¶
func NewTool(c Client, opts contract.ToolOptions[Client]) *DefaultTool
func (*DefaultTool) CopyHeaders ¶ added in v0.1.11
func (d *DefaultTool) CopyHeaders(ctx context.Context, dst, src *http.Request, headers ...string) error
CopyHeaders copies the specified headers from the source request to the destination request. If no headers are specified, all headers from the source request will be copied to the destination request.
func (*DefaultTool) DecodeBody ¶ added in v0.1.11
DecodeBody reads and unmarshals the request body into the provided variable.
func (*DefaultTool) DoWithTimeout ¶ added in v0.1.552
func (d *DefaultTool) DoWithTimeout(ctx context.Context, r *http.Request, t time.Duration) (*http.Response, error)
DoWithTimeout sends an HTTP request and returns an HTTP response bypassing the default timeout.
func (*DefaultTool) GetHeaders ¶ added in v0.1.11
GetHeaders extracts and returns all headers from an HTTP request as an http.Header map.
func (*DefaultTool) NewRequest ¶ added in v0.1.11
func (d *DefaultTool) NewRequest(ctx context.Context, method, url string, opts contract.RequestOptions) (*http.Request, error)
NewRequest creates a new HTTP request with the specified method, URL, and options.
func (*DefaultTool) OpenFile ¶ added in v0.1.377
func (d *DefaultTool) OpenFile(ctx context.Context, fsys http.FileSystem, name string) (http.File, error)
OpenFile attempts to open a file.
func (*DefaultTool) QueryString ¶ added in v0.1.11
QueryString constructs a query parameter string from a variadic number of key-value pairs. The values passed should not already be URL-escaped, as the function will handle escaping.
func (*DefaultTool) RespondJSON ¶ added in v0.1.11
func (d *DefaultTool) RespondJSON(ctx context.Context, w http.ResponseWriter, v any, status int, escapeHTML bool) error
RespondJSON writes the JSON data to the response writer with appropriate headers. The Content-Type header is set to application/json. The Content-Length header is set with the length of the uncompressed data. The Content-Length is not set if the Content-Encoding header is set to gzip. The status code is set based on the provided code parameter.
func (*DefaultTool) ServeContent ¶ added in v0.1.1022
func (d *DefaultTool) ServeContent(ctx context.Context, opts contract.ServeContentOptions) error
ServeContent serves content.
func (*DefaultTool) ServeFile ¶ added in v0.1.377
func (d *DefaultTool) ServeFile(ctx context.Context, opts contract.ServeFileOptions) error
ServeFile serves a static file.
func (*DefaultTool) ServeHTML ¶ added in v0.1.11
func (d *DefaultTool) ServeHTML(ctx context.Context, w http.ResponseWriter, body io.Reader, status int) error
ServeHTML writes an HTML response to the provided http.ResponseWriter with the given HTML content and HTTP status code.
func (*DefaultTool) SetQueryParams ¶ added in v0.1.326
func (d *DefaultTool) SetQueryParams(ctx context.Context, r *http.Request, q map[string][]string, override bool) error
SetQueryParams updates or appends query parameters.
func (*DefaultTool) ValidateQueryParams ¶ added in v0.1.11
func (d *DefaultTool) ValidateQueryParams(ctx context.Context, q map[string][]string, rules ...contract.QueryParamRule) error
ValidateQueryParams ...
func (*DefaultTool) Write ¶ added in v0.1.377
func (d *DefaultTool) Write(ctx context.Context, w http.ResponseWriter, b []byte) (int, error)
Write writes bytes to response.
type Dependencies ¶ added in v0.1.8
type Dependencies struct {
C contract.HTTPClient
M contract.Marshaler
U contract.Unmarshaler
F contract.FSysOperator
R contract.Reader
}