httpclient

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 25 Imported by: 1 module, 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

View Source
const MaximumPollBackoff = 15 * time.Minute

Variables

This section is empty.

Functions

func ExtractPath

func ExtractPath(root any, path string) (any, bool, error)

Extract a value using a validated selection path

func Interval

func Interval(method string, seconds float64) time.Duration

Interval enables automatic polling only for read-only methods

func ParsePath

func ParsePath(path string) ([]pathPart, error)

ParsePath supports dotted names, escaped delimiters, numeric indices and quoted literal keys. Empty paths select the root. Offsets are byte offsets

func ParseRetryAfter

func ParseRetryAfter(value string, now time.Time) time.Time

Parse bounded Retry-After seconds or a supported HTTP date

func PathSuggestions

func PathSuggestions(root any) []string

Suggest bounded selection paths from a decoded JSON value

func PollJitter

func PollJitter() float64

Choose a jitter factor for polling backoff

func RetryAt

func RetryAt(err error) time.Time

Extract the server retry deadline from a service error

func RetryDelay

func RetryDelay(interval time.Duration, failures int, jitter float64) time.Duration

Compute bounded failure backoff with caller-supplied jitter

func RetryLabel

func RetryLabel(next, now time.Time) string

Format the remaining retry delay for display

Types

type HTTPError

type HTTPError struct {
	Status int
	Retry  time.Time
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

Describe the service HTTP failure

func (*HTTPError) SafeError

func (e *HTTPError) SafeError() error

Drop response details while retaining status and retry information

type HTTPResult

type HTTPResult struct {
	PollingFeedback
	Status      int            `json:"status"`
	DurationMS  int64          `json:"duration_ms"`
	Fields      map[string]any `json:"fields"`
	Missing     []string       `json:"missing"`
	Preview     any            `json:"preview"`
	Paths       []string       `json:"paths"`
	Revalidated bool           `json:"revalidated,omitempty"`
	RetryAfter  time.Time      `json:"-"`
}

func Request

func Request(ctx context.Context, s map[string]any, options Options) (HTTPResult, error)

Perform a bounded HTTP request with preview and error handling

func RequestHTTP

func RequestHTTP(ctx context.Context, s map[string]any) (HTTPResult, error)

Perform an HTTP request with the default options

type Options

type Options struct {
	// VaultURL is an explicitly authorized secret endpoint. Its path, response,
	// and validators must never enter diagnostics or a shared cache.
	VaultURL      *sdk.VaultSecret
	Cache         *ValidatorCache
	Automatic     bool
	StatusOnly    bool
	NoRedirect    bool
	AllowUserInfo bool
}

func (Options) DisplayRequest added in v0.1.1

func (o Options) DisplayRequest(ctx context.Context, settings map[string]any) (HTTPResult, error)

DisplayRequest extracts configured fields without generating an inspector preview or path list.

type PollingFeedback

type PollingFeedback struct {
	Stale     bool   `json:"stale,omitempty"`
	NextRetry string `json:"next_retry,omitempty"`
	LastValue string `json:"last_successful_value,omitempty"`
	Failure   string `json:"failure,omitempty"`
}

type Service

type Service struct {
	Client          *http.Client
	MaximumResponse int64
}

func NewService

func NewService() *Service

Create a service client using normal TLS verification

func (*Service) Close

func (h *Service) Close()

Close idle service HTTP connections

func (*Service) Do

func (h *Service) Do(ctx context.Context, method, endpoint string, headers map[string]string, body []byte) ([]byte, error)

Perform a bounded service request and return its response bytes

func (*Service) JSON

func (h *Service) JSON(ctx context.Context, method, endpoint string, headers map[string]string, body any, out any) error

Encode a JSON request and decode the bounded response

type ValidatorCache

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

Private, process-local validator storage. Keys are salted digests of resolved requests/extraction, never plaintext URLs, headers or credentials. Values are already-redacted immutable JSON. Workers only share this bounded cache

func NewValidatorCache

func NewValidatorCache() *ValidatorCache

Create a bounded HTTP validator cache

func (*ValidatorCache) Reset

func (c *ValidatorCache) Reset()

Clear cached validators and response previews

Jump to

Keyboard shortcuts

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