Documentation
¶
Overview ¶
Package appconfig provides the logic for watching and reading application configuration values. Application configuration values may be static or they may be dynamically loaded from external systems such as Vault, Kubernetes, AWS SSM, etc.
Application configuration is primarily used by the entrypoint with Waypoint to load (and reload) configuration values. However, this package can be used standalone if application config wants to be pulled in anywhere.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
Option is used to configure NewWatcher.
func WithDynamicEnabled ¶
WithDynamicEnabled sets whether we allow dynamic sources or not. This defaults to true.
If this is disabled, then all dynamic config requests are ignored. They aren't set to empty values or anything, they simply aren't set at all.
func WithLogger ¶
func WithLogger(log hclog.Logger) Option
WithLogger sets the logger for the Watcher. If no logger is specified, the Watcher will use the default logger (hclog.L() value).
func WithNotify ¶
WithNotify notifies a channel whenever there are changes to the configuration values. This will stop receiving values when the watcher is closed.
Updates will block when attempting to send on this channel. However, while blocking, multiple updates may occur that will be coalesced to a follow up update when the channel send succeeds. Therefore, receivers will always eventually receive the full current env list, but may miss intermediate sets if they are slow to receive.
func WithPlugins ¶
WithPlugins sets a map of already-launched plugins to use for dynamic configuration sources.
func WithRefreshInterval ¶
WithRefreshInterval sets the interval between checking for new values from config source plugins that don't support edge triggers.
NOTE(mitchellh): At the time of writing, we don't support edge triggered plugins at all, but we plan to at some point so the docs reflect that.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher reads application configuration values and watches for any changes.
The values that the watcher is watching can be added, removed, or updated along with any configuration sources (how to read from external systems such as Vault).
func NewWatcher ¶
NewWatcher creates a new Watcher instance.
This will immediately start the background goroutine for reading and updating configuration values, even if no initial values are provided. You must call Close to properly clean up resources used by the Watcher.
func (*Watcher) Close ¶
Close stops all the background goroutines that this watcher started. This will block until all the background tasks have exited.
func (*Watcher) Next ¶
Next returns the next values for the configuration AFTER the given iterator value iter. A value of 0 can be used for iter for a first read.
The return value will be the configuration values in env format (KEY=VALUE), the current iterator value that you should use with the next call to Next, and any error if it occurred.
The ctx parameter can be used for timeouts, cancellation, etc. If the context is closed, this will return the context error.
func (*Watcher) UpdateSources ¶
UpdateSources updates the configuration sources for the watcher. The behavior and semantics are identical to UpdateVars but for configuration sources, so please see the documentation for UpdateVars for more details.
func (*Watcher) UpdateVars ¶
UpdateVars updates the variables for the watcher. This replaces all the previous set variables.
This may block for some time waiting for the update loop to accept our changes. The ctx parameter can be used as a timeout. If the context is cancelled, the error returned will be the context error.