Documentation
¶
Overview ¶
Package flags provides config-driven feature flags with hot-reload and percentage rollouts, requiring no external service.
Index ¶
- type Config
- type Flags
- func (f *Flags) Bool(ctx context.Context, name string, def bool) bool
- func (f *Flags) BoolFor(ctx context.Context, name, key string, def bool) bool
- func (f *Flags) Duration(ctx context.Context, name string, def time.Duration) time.Duration
- func (f *Flags) Float(ctx context.Context, name string, def float64) float64
- func (f *Flags) Int(ctx context.Context, name string, def int) int
- func (f *Flags) String(ctx context.Context, name, def string) string
- type Module
- func (m *Module) ConfigPath() string
- func (m *Module) Dependencies() ([]reflect.Type, []reflect.Type)
- func (m *Module) Init(ctx context.Context) error
- func (m *Module) LoadConfig(k *koanf.Koanf) error
- func (m *Module) OnReload(k *koanf.Koanf)
- func (m *Module) Provides() []reflect.Type
- func (m *Module) Shutdown(_ context.Context) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Instance name
Name string `koanf:"-"`
// Flags holds the raw flag definitions: scalars for plain values, or
// {value, rollout} objects for percentage rollouts. Prefer snake_case
// flag names; hyphens cannot be overridden via environment variables.
Flags map[string]any `koanf:"flags"`
}
Config represents configuration for the feature flags Module
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig returns default configuration
type Flags ¶
type Flags struct {
// contains filtered or unexported fields
}
Flags exposes lock-free reads over the current flag snapshot. The snapshot is swapped wholesale on config hot-reload, so reads never observe a half-applied reload.
func (*Flags) Bool ¶
Bool returns the flag's boolean value, or def if missing or mistyped. Rollout percentages are ignored; use Flags.BoolFor for rollout-aware reads.
func (*Flags) BoolFor ¶
BoolFor returns the flag's boolean value gated by its rollout percentage: a stable hash of the flag name and key decides whether key is in the enabled bucket. Without a rollout it behaves like Flags.Bool.
type Module ¶
Module provides config-driven Flags via DI, hot-reloaded on config change.
func (*Module) ConfigPath ¶
ConfigPath returns the koanf path for this module's configuration.
func (*Module) Dependencies ¶
Dependencies declares the optional types this module needs from DI before Init.
func (*Module) LoadConfig ¶
LoadConfig loads configuration from koanf.
func (*Module) OnReload ¶
OnReload re-parses flag definitions from the reloaded config, keeping the previous snapshot if the new one fails to parse. The OnReload contract provides no context, so use the default logger.