httpclt

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func JSONResponse[T any](ctx context.Context, meta Metadata) (_ *http.Response, o T, _ error)

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

type QueryStringer interface {
	QueryForm() (string, error)
}

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

type ResponseObject interface {
	DecodeJSON(d jsonflow.Decoder) error
}

ResponseObject is an interface that can decode the response body from JSON using streaming.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL