Documentation
¶
Overview ¶
Package source provides built-in contracts.Source implementations for the koanf-style WithSource(file/http/bytes, parser) call shape.
A Source is a byte-stream layer: Read returns (bytes, contentType, revision). The framework pairs it with a Parser (see pkg/parser) via Bind to obtain a Provider that participates in the reload pipeline. Already-structured sources (env, cli, KV-with-one-key-per-setting) continue to use the Provider contract directly — they have no need for a Parser.
Index ¶
- type BytesSource
- type FileSource
- type HTTPSource
- func (h *HTTPSource) Name() string
- func (h *HTTPSource) Priority() int
- func (h *HTTPSource) Read(ctx context.Context) ([]byte, string, string, error)
- func (h *HTTPSource) Watch(_ context.Context) (<-chan contracts.Event, error)
- func (h *HTTPSource) WithClient(c *http.Client) *HTTPSource
- func (h *HTTPSource) WithPriority(p int) *HTTPSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BytesSource ¶
type BytesSource struct {
// contains filtered or unexported fields
}
BytesSource is an in-memory byte buffer surfaced as a Source. Use it for tests, examples and bootstrap code that wants to inject inline configuration without writing a temporary file.
The contentType doubles as the parser hint: when WithSource is called with a nil Parser, the parser registry (pkg/parser) is consulted with this string. Either bare extensions ("yaml"), dotted forms (".yaml") or MIME types ("application/yaml") work.
func NewBytes ¶
func NewBytes(name, contentType string, data []byte) *BytesSource
NewBytes constructs a BytesSource. The default priority is 9000 (above file layers, below CLI), matching the legacy bytes-provider position in the merge order. Override via WithPriority.
func (*BytesSource) Priority ¶
func (b *BytesSource) Priority() int
Priority implements contracts.Source.
func (*BytesSource) WithPriority ¶
func (b *BytesSource) WithPriority(p int) *BytesSource
WithPriority returns b with priority overridden.
type FileSource ¶
type FileSource struct {
// contains filtered or unexported fields
}
FileSource reads a single auxiliary file (yaml/json/toml/...) at load time. Watching is handled by the global file-watcher subsystem rather than the Source; Watch returns (nil, nil).
The content-type returned by Read is the lowercase file extension without the leading dot ("yaml", "json", "toml"). Bind uses this hint to auto-select a Parser when WithSource is called with nil.
func NewFile ¶
func NewFile(path string) *FileSource
NewFile constructs a FileSource. Default priority is 8000 (above generator layers, below provider/CLI). Override via WithPriority.
func (*FileSource) Name ¶
func (f *FileSource) Name() string
Name implements contracts.Source. Returns "file:<path>".
func (*FileSource) Priority ¶
func (f *FileSource) Priority() int
Priority implements contracts.Source.
func (*FileSource) Read ¶
Read implements contracts.Source. A missing file is reported as an empty payload + empty rev (and no error) so the layer can be optional. Any other I/O error is propagated.
func (*FileSource) Watch ¶
Watch implements contracts.Source. The global file-watcher handles file changes; the Source itself does not subscribe.
func (*FileSource) WithPriority ¶
func (f *FileSource) WithPriority(p int) *FileSource
WithPriority overrides the default priority.
type HTTPSource ¶
type HTTPSource struct {
// contains filtered or unexported fields
}
HTTPSource fetches a single URL on every Read, honouring ETag / If-None-Match for cheap unchanged responses. The framework's global watcher does not poll HTTP — callers that want change notifications should pair an HTTPSource with a separate event stream provider (e.g. a webhook bridge).
HTTPSource caches the last successful body and ETag; on a 304 the cached body is replayed. The content-type hint comes from the response Content-Type header (lower-cased, parameter stripped).
func NewHTTP ¶
func NewHTTP(url string) *HTTPSource
NewHTTP constructs an HTTPSource pointing at url. The default http.Client has a 10-second timeout; override via WithClient if you need long-poll or different transport settings.
func (*HTTPSource) Name ¶
func (h *HTTPSource) Name() string
Name implements contracts.Source. Returns "http:<url>".
func (*HTTPSource) Priority ¶
func (h *HTTPSource) Priority() int
Priority implements contracts.Source.
func (*HTTPSource) Read ¶
Read implements contracts.Source. Performs a GET with the cached ETag (when present) in If-None-Match. On 304 returns the cached payload with the same revision string; on 200 caches and returns the fresh payload.
func (*HTTPSource) Watch ¶
Watch implements contracts.Source. HTTP polling is not provided by the Source contract; pair with a dedicated event-stream provider (or wrap with a poller) when change notifications are required.
func (*HTTPSource) WithClient ¶
func (h *HTTPSource) WithClient(c *http.Client) *HTTPSource
WithClient overrides the http.Client used for fetches.
func (*HTTPSource) WithPriority ¶
func (h *HTTPSource) WithPriority(p int) *HTTPSource
WithPriority overrides the default priority.