Documentation
¶
Overview ¶
Package config provides a tiny loader that populates a configuration struct from multiple sources with clear precedence:
- YAML file (if provided via WithYAML)
- Environment variables (optionally prefixed via WithEnvPrefix)
- Flags from a flag.FlagSet (default flag.CommandLine unless overridden via WithFlagSet)
Later sources override earlier ones (flags > env > YAML)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
RenewInterval = 1 * time.Minute
)
Functions ¶
Types ¶
type Option ¶
type Option func(*loader)
Option configures the loader used by Load Helpers (WithFlagSet, WithYAML, and WithEnvPrefix) can be used to customize how configuration sources are discovered and merged
func WithEnvPrefix ¶
WithEnvPrefix sets a prefix for all environment variables WithEnvPrefix("APP") causes "HOST" to be read from "APP_HOST"
func WithFlagSet ¶
WithFlagSet sets the flag.FlagSet that will be consulted for overrides Flags are evaluated last, giving them the highest precedence over environment variables and YAML values
type Rotator ¶
type Rotator struct {
// contains filtered or unexported fields
}
Rotator holds the default and current configuration and allows atomic updates. need dynamically update config in a thread-safe manner for all p2p nodes in the cluster
func NewConfigRotator ¶
func NewConfigRotator( ctx context.Context, log logger.AppLogger, baseOptCfg *entities.OptimumConfig, chainID, clusterID string, updater func(config *entities.DynamicConfig), opts ...RotatorOption, ) *Rotator
NewConfigRotator creates a new config rotator that periodically fetches and applies dynamic configuration from a remote endpoint. The rotator starts a background goroutine that fetches config at the specified interval. If chainID or clusterID is empty, fetching is disabled. If WithServiceVersion is provided, it is sent as the service_version query parameter. The updater function is called whenever a new config is successfully fetched and applied.
func (*Rotator) Get ¶
func (r *Rotator) Get() *entities.OptimumConfig
Get returns the current configuration. Thread-safe: uses atomic operations for concurrent access.
func (*Rotator) RenewConfig ¶
func (r *Rotator) RenewConfig(cfg *entities.DynamicConfig)
RenewConfig atomically updates the current configuration by applying the dynamic config. Thread-safe: uses atomic operations for concurrent access.
type RotatorOption ¶
type RotatorOption func(*Rotator)
RotatorOption configures a Rotator (e.g. WithRenewInterval).
func WithBootstrapBaseURL ¶
func WithBootstrapBaseURL(baseURL string) RotatorOption
WithBootstrapBaseURL overrides the default production bootstrap endpoint.
func WithRenewInterval ¶
func WithRenewInterval(d time.Duration) RotatorOption
WithRenewInterval sets the interval between config fetch attempts. If not set, RenewInterval is used.
func WithServiceVersion ¶
func WithServiceVersion(v string) RotatorOption
WithServiceVersion sets the optional service version used when fetching dynamic config.