http

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 8 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBodyTooLarge indicates the HTTP response body exceeded the configured max size.
	ErrBodyTooLarge = errors.New("http provider: body too large")
)

Functions

func IsRemoteURL

func IsRemoteURL(path string) bool

IsRemoteURL reports whether the given path is a remote HTTP(S) URL.

Types

type HTTP

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

HTTP provides configuration bytes fetched from an HTTP(S) endpoint. Required: URL. Optional: headers, timeout, custom client, HTTP method.

func New

func New(url string, opts ...Option) *HTTP

New creates an HTTP-backed Provider.

func (*HTTP) Read

func (h *HTTP) Read(ctx context.Context) ([]byte, error)

Read implements Provider by performing the HTTP request and returning the body bytes.

type Option

type Option func(*options)

Option configures optional behavior for the HTTP provider.

func WithClient

func WithClient(c *http.Client) Option

WithClient sets a custom HTTP client. When provided, it takes precedence over WithTimeout. The provided client will be used as-is.

func WithHeader

func WithHeader(key, value string) Option

WithHeader adds or overrides a single request header.

func WithHeaders

func WithHeaders(h http.Header) Option

WithHeaders merges multiple headers into the request headers.

func WithMaxBodySize

func WithMaxBodySize(n int64) Option

WithMaxBodySize limits the maximum response body size in bytes. If the response exceeds this size, Read returns ErrBodyTooLarge. A non-positive value disables the limit.

func WithMethod

func WithMethod(m string) Option

WithMethod sets the HTTP method. Default: GET.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets a client-level timeout for requests when using the internally created http.Client. Default: no timeout (0). Prefer controlling request deadlines with context (e.g., context.WithTimeout). If a custom client is supplied via WithClient, this option is ignored.

Jump to

Keyboard shortcuts

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