Documentation
¶
Overview ¶
Package http is a first-party HTTP/HTTPS provider for FastConf.
It performs periodic GETs against a configured URL, decodes the body using a registered FastConf Codec (yaml/json by default), and emits change events to drive Manager reloads. The implementation is the canonical "remote provider golden reference" for FastConf:
- Stateless: no goroutines outside the user-controlled Watch loop.
- ETag / If-None-Match aware: when the server supplies an ETag header, subsequent polls send If-None-Match and treat 304 as "unchanged" (no event, no reload work).
- Body-hash fallback: if the server omits ETag, the provider hashes the response body and only emits an event when the hash changes — preserves FastConf's "no spurious reload" guarantee.
- Pluggable HTTP client and clock for tests; default uses http.DefaultClient with a 10s timeout.
- Implements contracts.Provider so it slots into fastconf.WithProvider(...) directly.
The module is intentionally tiny and depends only on the standard library plus fastconf/contracts so it can be vendored as a reference when authoring proprietary remote providers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
Codec is the minimal byte→map decoder this provider needs. It matches contracts.Codec exactly so the user can pass any registered FastConf codec (yaml, json, toml-via-plugin, ...) without adapter.
type Doer ¶
Doer is the subset of *http.Client needed by Provider — anything implementing this contract can be injected for tests, retries, or authenticated transports.
type Option ¶
type Option func(*Provider)
Option mutates a Provider during construction. Use the With* helpers below to compose configuration without growing New's signature.
func WithClient ¶
WithClient injects an alternate HTTP client (e.g. one with auth or instrumented for traces). Default: http.DefaultClient.
func WithHeader ¶
WithHeader adds a static request header (Bearer tokens, tenant IDs, ...). Multiple calls accumulate.
func WithInterval ¶
WithInterval overrides the watch poll interval (default: 30s).
func WithPriority ¶
WithPriority overrides the default priority (PriorityKV).
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider polls an HTTP endpoint on a configurable interval and emits a change event whenever the response payload (or its ETag) differs from the last accepted one.
func New ¶
New constructs an HTTP-backed Provider. name is surfaced in Snapshot().Sources and metrics labels; codec decodes the response body. url MUST be absolute. A zero-value codec or empty url returns an error rather than panicking later in the reload loop.
func (*Provider) Load ¶
Load fetches the URL and returns the decoded payload. It updates the provider's ETag / body-hash bookkeeping so the next Watch tick can short-circuit unchanged responses. A 304 response returns the previously-loaded snapshot rather than an error.