utils

package
v0.20.0 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: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPDoer

type HTTPDoer interface {
	// DoRequest sends an HTTP request using the given parameters.
	//
	// Parameters:
	//   - ctx: A context controlling request timeout and cancellation.
	//   - method: The HTTP method to use (e.g. "GET", "POST").
	//   - url: The target URL of the HTTP request.
	//   - body: The request payload, typically JSON-encoded.
	//
	// Returns:
	//   - *http.Response: The raw HTTP response object.
	//   - error: Any error encountered during request creation or execution.
	DoRequest(ctx context.Context, method, url string, body []byte) (*http.Response, error)
}

HTTPDoer defines the interface required to perform an HTTP request.

It allows consumers to inject custom HTTP clients for testability and flexibility.

type HttpClient

type HttpClient struct {
	Headers      map[string]string // Headers are added to each outbound HTTP request.
	SkipInsecure bool              // SkipInsecure disables TLS certificate validation when true.
}

HttpClient implements the Doer interface with support for custom headers and TLS options.

func NewHttpClient

func NewHttpClient(headers map[string]string, skipInsecure bool) *HttpClient

NewHttpClient creates a configured HTTP client for issuing requests.

Parameters:

  • headers: A map of key-value headers to attach to each request.
  • skipInsecure: If true, TLS verification is disabled.

Returns:

  • *HttpClient: A client ready to send requests via DoRequest.

func (*HttpClient) DoRequest

func (hc *HttpClient) DoRequest(ctx context.Context, method, url string, body []byte) (*http.Response, error)

DoRequest builds and sends an HTTP request with the given payload and configuration.

Parameters:

  • ctx: The request-scoped context for cancellation and timeout.
  • method: The HTTP method to use (e.g. "POST").
  • url: The request destination.
  • body: The payload to include in the request body.

Returns:

  • *http.Response: The HTTP response from the remote server.
  • error: An error if the request fails to be built or sent.

Jump to

Keyboard shortcuts

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