Documentation ¶
Index ¶
- Constants
- Variables
- func AddFeatureSpec(key Feature, spec FeatureSpec) error
- func Enabled(key Feature) bool
- func ExecuteInitFunc(keys ...Feature)
- func FinallyInitFunc()
- func KnownFeatures() map[string]bool
- func Set(value string) error
- func SetFeatureState(key Feature, enable bool) error
- func SetFromMap(m map[string]bool) error
- 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) ExecuteInitFunc(keys ...Feature)
- func (fg *FeatureGate) FinallyInitFunc()
- func (fg *FeatureGate) KnownFeatures() map[string]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) 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 ¶
Functions ¶
func AddFeatureSpec ¶
func AddFeatureSpec(key Feature, spec FeatureSpec) error
func ExecuteInitFunc ¶ added in v0.22.0
func ExecuteInitFunc(keys ...Feature)
func FinallyInitFunc ¶ added in v0.22.0
func FinallyInitFunc()
func KnownFeatures ¶ added in v0.12.0
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) ExecuteInitFunc ¶ added in v0.22.0
func (fg *FeatureGate) ExecuteInitFunc(keys ...Feature)
ExecuteInitFunc calls the known feature specs in order. When the function is called for the first time, set the inited flag to prevent the known feature specs changed.
func (*FeatureGate) FinallyInitFunc ¶ added in v0.22.0
func (fg *FeatureGate) FinallyInitFunc()
FinallyInitFunc calls all known feature specs asynchronously. If a feature spec has already finished init in ExecuteInitFunc, ignore it.
func (*FeatureGate) KnownFeatures ¶ added in v0.12.0
func (fg *FeatureGate) KnownFeatures() map[string]bool
KnownFeatures returns a slice of strings describing the FeatureGate's known features and status.
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) 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 ExecuteInitFunc or FinallyInitFunc is invoked InitFunc() // PreRelease indicates the maturity level of the feature PreRelease() prerelease }