httputils

package
v0.0.0-...-7dfa3a9 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 9 modules, 6 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

View Source
var (
	// ErrInvalidSlackWebhookURL is returned when the Slack webhook URL is invalid.
	ErrInvalidSlackWebhookURL = errors.New(
		"invalid Slack webhook URL. Must be a valid https://hooks.slack.com/services/ URL")
)
View Source
var (
	ErrUnableToParseURL = errors.New("unable to parse URL")
)

Functions

func ValidateSlackWebhookURL

func ValidateSlackWebhookURL(webhookURL string) error

ValidateSlackWebhookURL validates the URL matches the expected Slack webhook URL format as defined by https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/ Ex. "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"

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