Documentation
¶
Overview ¶
Package flags is GTB's wiring for dynamic feature flags (spec 0199 D10, D11): a features.Backend over the tool's own config store, so a service's flags can be flipped by editing its config with no vendor at all, and the controls registration that gives any backend the controller's lifecycle.
Index ¶
- Variables
- func ConfigKey(id features.ID) string
- func RegisterBackend(ctrl *controls.Controller, name string, backend features.Backend)
- type ConfigBackend
- func (b *ConfigBackend) Close() error
- func (b *ConfigBackend) Init(context.Context) error
- func (b *ConfigBackend) Ready() bool
- func (b *ConfigBackend) Resolve(_ context.Context, id features.ID, fallback bool, _ features.EvalContext) (features.Decision, error)
- func (b *ConfigBackend) Watch(context.Context) <-chan features.Change
Constants ¶
This section is empty.
Variables ¶
var ErrNotABool = errors.NewSentinel("gtb.flags.not_a_bool", "flags: a feature's enabled value must be a boolean")
ErrNotABool reports a features.<id>.enabled value that is not a boolean.
Functions ¶
func ConfigKey ¶
ConfigKey is the config path the config-store backend reads for a feature: features.<id>.enabled. Absent means "no override".
func RegisterBackend ¶
func RegisterBackend(ctrl *controls.Controller, name string, backend features.Backend)
RegisterBackend registers backend as a controls service named name, so its Init runs on the controller's start and its Close on stop (spec 0199 D10): a streaming vendor backend then opens and closes with the service that evaluates against it.
Types ¶
type ConfigBackend ¶
type ConfigBackend struct {
// contains filtered or unexported fields
}
ConfigBackend resolves dynamic features from the tool's config store. It takes a fresh view on every Resolve, so a reload is visible at once and there is no cache to go stale (the spike measured the view read at 135 ns either way). A store reload is forwarded on Watch as "everything may have changed", since the store does not say which keys moved.
func NewConfigBackend ¶
func NewConfigBackend(store *config.Store) *ConfigBackend
NewConfigBackend builds a backend over store.
func (*ConfigBackend) Close ¶
func (b *ConfigBackend) Close() error
Close releases nothing: the store's lifecycle is the tool's.
func (*ConfigBackend) Init ¶
func (b *ConfigBackend) Init(context.Context) error
Init subscribes to the store's reloads. The store is loaded before it is handed to anything, so the backend is ready at once.
func (*ConfigBackend) Ready ¶
func (b *ConfigBackend) Ready() bool
Ready is always true: a store is loaded before anything holds it, so there is nothing to wait for. Init only wires the change notices.
func (*ConfigBackend) Resolve ¶
func (b *ConfigBackend) Resolve(_ context.Context, id features.ID, fallback bool, _ features.EvalContext) (features.Decision, error)
Resolve reads features.<id>.enabled. An absent key is a clean Disabled answer (the fallback, the Set state, applies); a present boolean is the backend's answer; anything else is ErrNotABool.