httputils

package
v0.0.0-...-4788987 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnableToParseURL = errors.New("unable to parse URL")
)

Functions

This section is empty.

Types

type FetchOption

type FetchOption func(*FetchOptions)

FetchOption is a function that modifies the FetchOptions.

func WithExpectedStatusCodes

func WithExpectedStatusCodes(codes []int) FetchOption

WithExpectedStatusCodes sets the expected status codes for the HTTP response.

func WithHeaders

func WithHeaders(headers map[string]string) FetchOption

WithHeaders sets the headers for the HTTP request.

type FetchOptions

type FetchOptions struct {
	Request  RequestOptions
	Response ResponseOptions
}

FetchOptions holds options for an HTTP fetch operation.

type HTTPFetcher

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

func NewHTTPFetcher

func NewHTTPFetcher(
	endpoint string, httpClient *http.Client) (*HTTPFetcher, error)

NewHTTPFetcher creates a new HTTPFetcher with the given endpoint and HTTP client.

func (HTTPFetcher) Fetch

func (f HTTPFetcher) Fetch(ctx context.Context, opts ...FetchOption) (io.ReadCloser, error)

Fetch performs an HTTP GET request to the configured endpoint. It returns the response body as an io.ReadCloser on success. The caller is responsible for closing the reader. It accepts a variable number of FetchOption functions to customize the request and response handling.

type RequestOptions

type RequestOptions struct {
	Headers map[string]string
}

RequestOptions holds options for the HTTP request.

type ResponseOptions

type ResponseOptions struct {
	// A list of status codes that are considered successful. If empty, only http.StatusOK is considered successful.
	ExpectedStatusCodes []int
}

ResponseOptions holds options for handling the HTTP response.

Jump to

Keyboard shortcuts

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