Documentation ¶
Index ¶
- Constants
- Variables
- func AddFeatureSpec(key Feature, spec FeatureSpec) error
- func Enabled(key Feature) bool
- func Set(value string) error
- func SetFeatureState(key Feature, enable bool) error
- func SetFromMap(m map[string]bool) error
- func StartInit()
- func Subscribe(key Feature, timeout time.Duration) (bool, error)
- func WaitInitFinsh() error
- type BaseFeatureSpec
- type Feature
- type FeatureGate
- func (fg *FeatureGate) AddFeatureSpec(key Feature, spec FeatureSpec) error
- func (fg *FeatureGate) Enabled(key Feature) bool
- func (fg *FeatureGate) Set(value string) error
- func (fg *FeatureGate) SetFeatureState(key Feature, enable bool) error
- func (fg *FeatureGate) SetFromMap(m map[string]bool) error
- func (fg *FeatureGate) StartInit()
- func (fg *FeatureGate) Subscribe(key Feature, timeout time.Duration) (bool, error)
- func (fg *FeatureGate) WaitInitFinsh() error
- type FeatureSpec
Constants ¶
const ( // Values for PreRelease. Alpha = prerelease("ALPHA") Beta = prerelease("BETA") GA = prerelease("") )
Variables ¶
var ( ErrInited = errors.New("feature gate is already inited") ErrNotInited = errors.New("feature gate is not inited") )
Functions ¶
func AddFeatureSpec ¶
func AddFeatureSpec(key Feature, spec FeatureSpec) error
func SetFeatureState ¶
func SetFromMap ¶
func WaitInitFinsh ¶
func WaitInitFinsh() error
Types ¶
type BaseFeatureSpec ¶
type BaseFeatureSpec struct { DefaultValue bool IsLockedDefault bool PreReleaseValue prerelease // contains filtered or unexported fields }
BaseFeatureSpec is a basic implementation of FeatureSpec. Usually, a feature spec just need an init func.
func (*BaseFeatureSpec) Default ¶
func (spec *BaseFeatureSpec) Default() bool
func (*BaseFeatureSpec) InitFunc ¶
func (spec *BaseFeatureSpec) InitFunc()
func (*BaseFeatureSpec) LockToDefault ¶
func (spec *BaseFeatureSpec) LockToDefault() bool
func (*BaseFeatureSpec) PreRelease ¶
func (spec *BaseFeatureSpec) PreRelease() prerelease
func (*BaseFeatureSpec) SetState ¶
func (spec *BaseFeatureSpec) SetState(enable bool)
func (*BaseFeatureSpec) State ¶
func (spec *BaseFeatureSpec) State() bool
type FeatureGate ¶
type FeatureGate struct {
// contains filtered or unexported fields
}
func NewFeatureGate ¶
func NewFeatureGate() *FeatureGate
func (*FeatureGate) AddFeatureSpec ¶
func (fg *FeatureGate) AddFeatureSpec(key Feature, spec FeatureSpec) error
AddFeatureSpec adds feature to the featureGate. features should be added by AddFeatureSpec
func (*FeatureGate) Enabled ¶
func (fg *FeatureGate) Enabled(key Feature) bool
Enabled returns true if the key is enabled.
func (*FeatureGate) Set ¶
func (fg *FeatureGate) Set(value string) error
Set parses and stores flag gates for known features from a string like feature1=true,feature2=false,...
func (*FeatureGate) SetFeatureState ¶
func (fg *FeatureGate) SetFeatureState(key Feature, enable bool) error
SetFeatureState sets feature enablement state for the feature
func (*FeatureGate) SetFromMap ¶
func (fg *FeatureGate) SetFromMap(m map[string]bool) error
SetFromMap stores flag gates for known features from a map[string]bool or returns an error
func (*FeatureGate) StartInit ¶
func (fg *FeatureGate) StartInit()
StartInit triggers init functions of feature
func (*FeatureGate) Subscribe ¶
Subscribe waits the feature is ready, and returns the feature is enabled or not. The timeout is the max wait time duration for subscribe. If timeout is zero, means no timeout.
func (*FeatureGate) WaitInitFinsh ¶
func (fg *FeatureGate) WaitInitFinsh() error
type FeatureSpec ¶
type FeatureSpec interface { // Default is the default enablement state for the feature Default() bool // LockToDefault indicates that the feature is locked to its default and cannot be changed LockToDefault() bool // SetState sets the enablement state for the feature SetState(enable bool) // State indicates the feature enablement State() bool // InitFunc used to init process when StartInit is invoked InitFunc() // PreRelease indicates the maturity level of the feature PreRelease() prerelease }