package feature
import "github.com/influxdata/flux/internal/pkg/feature"
Package feature provides feature flagging capabilities for a Go application.
Flags are defined using the `MakeXXXFlag` functions. These can either be defined in code or generated using the feature generator included in this module.
Flags are configured in `flags.yml` at the top of this repository. Running `make flags` generates Go code based on this configuration to programmatically test flag values in a given request context. Boolean flags are the most common case, but integers, floats and strings are supported for more complicated experiments.
The `Flagger` interface is the crux of this package. It computes a map of feature flag values for a given request context. The implementation is application dependent. The result can be attached to the context using `Annotate` and then the results will be used when checking feature flags.
Flags can be checked using the context after it has been annotated. For example, to check a boolean flag that was generated by the `feature` command, you might do it this way:
if feature.MyFeature().Enabled(ctx) { // my feature is enabled } else { // my feature is disabled }
Index ¶
- func Inject(ctx context.Context, flagger Flagger) context.Context
- func SetMetrics(m Metrics)
- type Base
- func MakeBase(name, key, owner string, defaultValue interface{}) Base
- func (f Base) Default() interface{}
- func (f Base) Key() string
- type BoolFlag
- func MakeBoolFlag(name, key, owner string, defaultValue bool) BoolFlag
- func (f BoolFlag) Enabled(ctx context.Context) (v bool)
- type Flag
- type Flagger
- type FloatFlag
- func MakeFloatFlag(name, key, owner string, defaultValue float64) FloatFlag
- func (f FloatFlag) Float(ctx context.Context) (v float64)
- type IntFlag
- func MakeIntFlag(name, key, owner string, defaultValue int) IntFlag
- func (f IntFlag) Int(ctx context.Context) (v int)
- type Metrics
- type StringFlag
Functions ¶
func Inject ¶
Inject will inject the Flagger into the context.
func SetMetrics ¶
func SetMetrics(m Metrics)
SetMetrics sets the metric store for feature flags.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base implements the base of the Flag type.
func MakeBase ¶
MakeBase constructs a flag.
func (Base) Default ¶
func (f Base) Default() interface{}
Default returns the type-agnostic zero value for the flag.
func (Base) Key ¶
Key returns the programmatic backend identifier for the flag.
type BoolFlag ¶
type BoolFlag struct { Base // contains filtered or unexported fields }
BoolFlag implements Flag for boolean values.
func MakeBoolFlag ¶
MakeBoolFlag returns a string flag with the given Base and default.
func (BoolFlag) Enabled ¶
Enabled indicates whether flag is true or false on the request context.
type Flag ¶
type Flag interface { // Key returns the programmatic backend identifier for the flag. Key() string // Default returns the type-agnostic zero value for the flag. // Type-specific flag implementations may expose a typed default // (e.g. BoolFlag includes a boolean Default field). Default() interface{} }
Flag represents a generic feature flag with a key and a default.
func MakeFlag ¶
MakeFlag constructs a Flag. The concrete implementation is inferred from the provided default.
type Flagger ¶
type Flagger interface { // FlagValue returns the value for a given flag. FlagValue(ctx context.Context, flag Flag) interface{} }
Flagger returns flag values.
func GetFlagger ¶
GetFlagger returns the Flagger for this context or the default flagger.
type FloatFlag ¶
type FloatFlag struct { Base // contains filtered or unexported fields }
FloatFlag implements Flag for float values.
func MakeFloatFlag ¶
MakeFloatFlag returns a string flag with the given Base and default.
func (FloatFlag) Float ¶
Float value of the flag on the request context.
type IntFlag ¶
type IntFlag struct { Base // contains filtered or unexported fields }
IntFlag implements Flag for integer values.
func MakeIntFlag ¶
MakeIntFlag returns a string flag with the given Base and default.
func (IntFlag) Int ¶
Int value of the flag on the request context.
type Metrics ¶
type Metrics interface { Inc(key string, value interface{}) }
type StringFlag ¶
type StringFlag struct { Base // contains filtered or unexported fields }
StringFlag implements Flag for string values.
func MakeStringFlag ¶
func MakeStringFlag(name, key, owner string, defaultValue string) StringFlag
MakeStringFlag returns a string flag with the given Base and default.
func (StringFlag) String ¶
func (f StringFlag) String(ctx context.Context) (v string)
String value of the flag on the request context.
Source Files ¶
doc.go feature.go flag.go metrics.go
Directories ¶
Path | Synopsis |
---|---|
internal/pkg/feature/cmd | |
internal/pkg/feature/cmd/feature | Sprig Copyright (C) 2013 Masterminds |
- Version
- v0.196.1 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 1 day ago –
Tools for package owners.