Documentation
¶
Index ¶
- func AddTraceToRequest(reqUuid string, req *http.Request, logger *slog.Logger) *http.Request
- func CloseBody(resp *http.Response) error
- func DrainCloseBody(resp *http.Response) error
- func NewHTTPClient(httpV HttpVersion) (*http.Client, error)
- type DoTimeRepeatClient
- type ErrorHandler
- type HttpVersion
- type ResponseHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTraceToRequest ¶
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 DrainCloseBody ¶
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.
type ErrorHandler ¶
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 ¶
ResponseHandler defines a function type to handle HTTP responses.