Documentation
¶
Overview ¶
Package feature implements a simple abstraction for feature flags with dynamic values.
Index ¶
- Variables
- type Flag
- type FlagKind
- type FlagSet
- func (s *FlagSet) All(yield func(Flag) bool)
- func (s *FlagSet) Bool(name string, value bool, desc string) func(context.Context) bool
- func (s *FlagSet) Context(ctx context.Context, values ...Value) context.Context
- func (s *FlagSet) Float(name string, value float64, desc string) func(context.Context) float64
- func (s *FlagSet) Int(name string, value int, desc string) func(context.Context) int
- func (s *FlagSet) Lookup(name string) (Flag, bool)
- func (s *FlagSet) String(name string, value string, desc string) func(context.Context) string
- func (s *FlagSet) Uint(name string, value uint, desc string) func(context.Context) uint
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrDuplicateFlag = errors.New("duplicate flag")
ErrDuplicateFlag is thrown by methods like FlagSet.Bool if a flag with a given name is already registered.
Functions ¶
This section is empty.
Types ¶
type Flag ¶
type Flag struct { // Kind contains the flags kind or type. Kind FlagKind // Name is the name of the feature flag. Name string // Value is the default value for the flag as specified on creation. Value any // Description is an optional description specified using [WithDescription]. Description string }
Flag represents a flag registered with a FlagSet.
type FlagKind ¶ added in v0.7.0
type FlagKind uint8
FlagKind is an enum of potential flag kinds.
const ( // FlagKindInvalid is the zero value of FlagKind and is not considered valid value. FlagKindInvalid FlagKind = iota // FlagKindBool denotes a boolean flag created using [FlagSet.Bool]. FlagKindBool // FlagKindInt denotes a boolean flag created using [FlagSet.Int]. FlagKindInt // FlagKindFloat denotes a boolean flag created using [FlagSet.Float]. FlagKindFloat // FlagKindString denotes a boolean flag created using [FlagSet.String]. FlagKindString // FlagKindUint denotes a boolean flag created using [FlagSet.Uint]. FlagKindUint )
type FlagSet ¶ added in v0.6.0
type FlagSet struct {
// contains filtered or unexported fields
}
FlagSet represents a set of defined feature flags.
The zero value is valid and returns zero values for all flags.
A FlagSet must not be copied and should instead be passed around via pointer.
func (*FlagSet) Bool ¶ added in v0.6.0
Bool registers a new flag that represents a boolean value.
If a Flag with the same name is already registered, the call will panic with an error that is ErrDuplicateFlag.
func (*FlagSet) Context ¶ added in v0.7.0
Context returns a new context based on ctx which will use the given values when checking feature flags of this set.
If a values type does not match the flags type, Context will panic.
Values with no matching flag are ignored.
func (*FlagSet) Float ¶ added in v0.6.0
Float registers a new flag that represents a float value.
If a Flag with the same name is already registered, the call will panic with an error that is ErrDuplicateFlag.
func (*FlagSet) Int ¶ added in v0.6.0
Int registers a new flag that represents an int value.
If a Flag with the same name is already registered, the call will panic with an error that is ErrDuplicateFlag.
func (*FlagSet) String ¶ added in v0.6.0
String registers a new flag that represents a string value.
If a Flag with the same name is already registered, the call will panic with an error that is ErrDuplicateFlag.
type Value ¶ added in v0.7.0
type Value struct {
// contains filtered or unexported fields
}
Value specifies a custom value for a feature flag, which can be assigned to a context.Context.
A Value must be created using one of BoolValue, FloatValue, IntValue, StringValue or UintValue.
func BoolValue ¶ added in v0.7.0
BoolValue returns a Value that can be passed to FlagSet.Context to override the value for the given flag.
func FloatValue ¶ added in v0.7.0
FloatValue returns a Value that can be passed to FlagSet.Context to override the value for the given flag.
func IntValue ¶ added in v0.7.0
IntValue returns a Value that can be passed to FlagSet.Context to override the value for the given flag.
func StringValue ¶ added in v0.7.0
StringValue returns a Value that can be passed to FlagSet.Context to override the value for the given flag.