client

package
v0.0.0-...-5eb588b Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTraceToRequest

func AddTraceToRequest(reqUuid string, req *http.Request, logger *slog.Logger) *http.Request

AddTraceToRequest adds HTTP tracing to the given request for logging connection and DNS events.

reqUuid: unique identifier for the request
req: HTTP request to add tracing to
logger: logger for trace events

Returns a new *http.Request with tracing enabled.

func CloseBody

func CloseBody(resp *http.Response) error

CloseBody closes the response body.

func DrainCloseBody

func DrainCloseBody(resp *http.Response) error

DrainCloseBody drains and closes the response body.

func NewHTTPClient

func NewHTTPClient(httpV HttpVersion) (*http.Client, error)

NewHTTPClient creates a new *http.Client configured for the specified HTTP version.

httpV: HTTP protocol version to use

Returns a pointer to http.Client or an error if the version is invalid.

Types

type DoTimeRepeatClient

type DoTimeRepeatClient struct {
	// contains filtered or unexported fields
}

DoTimeRepeatClient is an HTTP client that can repeat requests and log timing information.

func NewDoTimeRepeatClient

func NewDoTimeRepeatClient(req *http.Request, logger *slog.Logger, httpV HttpVersion) (*DoTimeRepeatClient, error)

NewDoTimeRepeatClient creates a new DoTimeRepeatClient with the given request, logger, and HTTP version.

req: base HTTP request to use for each repeated request
logger: logger for tracing and timing
httpV: HTTP protocol version to use

Returns a pointer to DoTimeRepeatClient or an error if the HTTP client cannot be created.

func (*DoTimeRepeatClient) DoTimeRepeat

func (c *DoTimeRepeatClient) DoTimeRepeat(ctx context.Context, n int, rh ResponseHandler, eh ErrorHandler) error

DoTimeRepeat sends the HTTP request n times, handling responses and errors with the provided handlers. It logs timing and tracing information for each request.

ctx: context for request cancellation and deadlines
n: number of times to repeat the request
rh: handler for processing HTTP responses
eh: handler for processing errors

Use the ErrorHandler parameter to define what errors should cause it to abort.

func (*DoTimeRepeatClient) LogErr

func (c *DoTimeRepeatClient) LogErr(reqUuid string, err error) error

LogErr logs the error with the logger set at the client adding the request UUID information.

type ErrorHandler

type ErrorHandler func(reqUuid string, err error) error

ErrorHandler defines a function type to handle errors.

type HttpVersion

type HttpVersion uint8

HttpVersion represents the HTTP protocol version to use in the client.

const (
	// HTTP1 represents HTTP/1.x protocol.
	HTTP1 HttpVersion = iota + 1
	// HTTP2 represents HTTP/2 protocol.
	HTTP2 HttpVersion = iota + 1

	UuidLogField = "req_uuid"
)

type ResponseHandler

type ResponseHandler func(resp *http.Response) error

ResponseHandler defines a function type to handle HTTP responses.

Jump to

Keyboard shortcuts

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