Documentation ¶
Overview ¶
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 ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetMetrics ¶ added in v0.156.0
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.
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.
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.
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.
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.
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.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
feature
Sprig Copyright (C) 2013 Masterminds Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
Sprig Copyright (C) 2013 Masterminds Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |