Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DoRequest = func(req *http.Request, meta Metadata, fn func(io.Reader) error) (*http.Response, error) { resp, err := http.DefaultClient.Do(req) if err != nil { return nil, err } defer func() { _ = resp.Body.Close() }() if err = fn(resp.Body); err != nil { return nil, err } return resp, nil }
DoRequest is a function that performs the actual HTTP request.
Functions ¶
func JSONResponse ¶
JSONResponse decodes the response body into a generic JSON object.
func ObjectResponse ¶
func ObjectResponse[T ResponseObject](ctx context.Context, o T, meta Metadata) (*http.Response, T, error)
ObjectResponse decodes the response body into a given object using streaming JSON parsing.
Types ¶
type Metadata ¶
type Metadata struct {
Target string // Service name or IP:PORT
Schema string // HTTP protocol (e.g., http, https)
Method string // HTTP method (GET, POST, etc.)
Pattern string // Request path, usually with placeholders (for REST)
RawPath string // Request path with placeholders processed
Query QueryStringer // Query string after the '?' part
Body any // Request body
Header http.Header // Request headers
Config map[string]string // Additional configuration options
}
Metadata holds contextual information for an HTTP request.
func CombineMetadata ¶
func CombineMetadata(meta Metadata, opts ...RequestOption) Metadata
CombineMetadata applies the given RequestOptions to the Metadata.
type QueryStringer ¶
QueryStringer defines the method to convert an object to a query string format (e.g., "key1=value1&key2=value2").
type RequestOption ¶
type RequestOption func(meta *Metadata)
RequestOption is a function that modifies the Metadata.
func WithConfig ¶
func WithConfig(config map[string]string) RequestOption
WithConfig is a RequestOption that adds the given configuration map to the Metadata.
func WithHeader ¶
func WithHeader(header http.Header) RequestOption
WithHeader is a RequestOption that adds the given HTTP headers to the Metadata.
type ResponseObject ¶
ResponseObject is an interface that can decode the response body from JSON using streaming.