Documentation
¶
Index ¶
- type ClientFilter
- type Conditions
- type EvaluationResult
- type FeatureFilter
- type FeatureFilterEvaluationContext
- type FeatureFlag
- type FeatureFlagProvider
- type FeatureManagement
- type FeatureManager
- func (fm *FeatureManager) GetFeatureNames() []string
- func (fm *FeatureManager) GetVariant(featureName string, appContext any) (*Variant, error)
- func (fm *FeatureManager) IsEnabled(featureName string) (bool, error)
- func (fm *FeatureManager) IsEnabledWithAppContext(featureName string, appContext any) (bool, error)
- type GroupAllocation
- type Options
- type PercentileAllocation
- type RequirementType
- type StatusOverride
- type TargetingAudience
- type TargetingContext
- type TargetingExclusion
- type TargetingFilter
- type TargetingFilterParameters
- type TargetingGroup
- type Telemetry
- type TimeWindowFilter
- type TimeWindowFilterParameters
- type UserAllocation
- type Variant
- type VariantAllocation
- type VariantAssignmentReason
- type VariantDefinition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientFilter ¶
type ClientFilter struct {
// Name is the identifier for this filter type
Name string `json:"name"`
// Parameters are the configuration values for the filter
Parameters map[string]any `json:"parameters,omitempty"`
}
ClientFilter represents a filter that must be evaluated for feature enablement
type Conditions ¶
type Conditions struct {
// RequirementType determines if any or all filters must be satisfied
// Values: "Any" or "All"
RequirementType RequirementType `json:"requirement_type,omitempty"`
// ClientFilters are the filter conditions that must be evaluated by the client
ClientFilters []ClientFilter `json:"client_filters,omitempty"`
}
Conditions defines the rules for enabling a feature dynamically
type EvaluationResult ¶ added in v1.1.0
type EvaluationResult struct {
// Feature contains the evaluated feature flag
Feature *FeatureFlag
// Enabled indicates the final state of the feature after evaluation
Enabled bool
// TargetingID is the identifier used for consistent targeting
TargetingID string
// Variant is the selected variant (if any)
Variant *Variant
// VariantAssignmentReason explains why the variant was assigned
VariantAssignmentReason VariantAssignmentReason
}
EvaluationResult contains information about a feature flag evaluation
type FeatureFilter ¶
type FeatureFilter interface {
// Name returns the identifier for this filter
Name() string
// Evaluate determines whether a feature should be enabled based on the provided contexts
Evaluate(evalCtx FeatureFilterEvaluationContext, appCtx any) (bool, error)
}
FeatureFilter defines the interface for feature flag filters. Filters determine whether a feature should be enabled based on certain conditions.
Example custom filter:
type EnvironmentFilter struct{}
func (f EnvironmentFilter) Name() string {
return "EnvironmentFilter"
}
func (f EnvironmentFilter) Evaluate(evalCtx FeatureFilterEvaluationContext, appCtx any) (bool, error) {
// Implementation
// ...
}
// Register custom filter with feature manager
manager, _ := featuremanagement.NewFeatureManager(
provider,
[]featuremanagement.FeatureFilter{&EnvironmentFilter{}},
)
type FeatureFilterEvaluationContext ¶
type FeatureFilterEvaluationContext struct {
// FeatureName is the name of the feature being evaluated
FeatureName string
// Parameters contains the filter-specific configuration parameters
Parameters map[string]any
}
FeatureFilterEvaluationContext provides the context information needed to evaluate a feature filter.
type FeatureFlag ¶
type FeatureFlag struct {
// ID uniquely identifies the feature
ID string `json:"id"`
// Description provides details about the feature's purpose
Description string `json:"description,omitempty"`
// DisplayName is a human-friendly name for display purposes
DisplayName string `json:"display_name,omitempty"`
// Enabled indicates if the feature is on or off
Enabled bool `json:"enabled"`
// Conditions defines when the feature should be dynamically enabled
Conditions *Conditions `json:"conditions,omitempty"`
// Variants represents different configurations of this feature
Variants []VariantDefinition `json:"variants,omitempty"`
// Allocation determines how variants are assigned to users
Allocation *VariantAllocation `json:"allocation,omitempty"`
// Telemetry contains feature flag telemetry configuration
Telemetry *Telemetry `json:"telemetry,omitempty"`
}
FeatureFlag represents a feature flag definition according to the v2.0.0 schema
type FeatureFlagProvider ¶
type FeatureFlagProvider interface {
// GetFeatureFlag retrieves a specific feature flag by its name.
//
// Parameters:
// - name: The name of the feature flag to retrieve
//
// Returns:
// - FeatureFlag: The feature flag if found
// - error: An error if the feature flag cannot be found or retrieved
GetFeatureFlag(name string) (FeatureFlag, error)
// GetFeatureFlags retrieves all available feature flags.
//
// Returns:
// - []FeatureFlag: A slice of all available feature flags
// - error: An error if the feature flags cannot be retrieved
GetFeatureFlags() ([]FeatureFlag, error)
}
FeatureFlagProvider defines the interface for retrieving feature flags from a source. Implementations of this interface can fetch feature flags from various configuration stores such as Azure App Configuration, local JSON files, or other sources.
type FeatureManagement ¶
type FeatureManagement struct {
FeatureFlags []FeatureFlag `json:"feature_flags"`
}
type FeatureManager ¶
type FeatureManager struct {
// contains filtered or unexported fields
}
FeatureManager is responsible for evaluating feature flags and their variants. It is the main entry point for interacting with the feature management library.
func NewFeatureManager ¶
func NewFeatureManager(provider FeatureFlagProvider, options *Options) (*FeatureManager, error)
NewFeatureManager creates and initializes a new instance of the FeatureManager. This is the entry point for using feature management functionality.
Parameters:
- provider: A FeatureFlagProvider that supplies feature flag definitions from a source such as Azure App Configuration or a local JSON file
- *options: Configuration options for the FeatureManager, including custom filters for conditional feature evaluation
Returns:
- *FeatureManager: A configured feature manager instance ready for use
- error: An error if initialization fails
func (*FeatureManager) GetFeatureNames ¶
func (fm *FeatureManager) GetFeatureNames() []string
GetFeatureNames returns the names of all available features.
Returns:
- []string: A slice containing the names of all available features
func (*FeatureManager) GetVariant ¶ added in v1.1.0
func (fm *FeatureManager) GetVariant(featureName string, appContext any) (*Variant, error)
GetVariant returns the assigned variant for a feature flag. This method is used for implementing multivariate feature flags, A/B testing, or feature configurations that change based on the user base and user interactions.
Parameters:
- featureName: The name of the feature to evaluate
- appContext: An optional context object for contextual evaluation
Returns:
- Variant: The assigned variant with its name and configuration value. If no variant is assigned, this will be nil.
- error: An error if the feature flag cannot be found or evaluated
func (*FeatureManager) IsEnabled ¶
func (fm *FeatureManager) IsEnabled(featureName string) (bool, error)
IsEnabled determines if a feature flag is enabled. This is the primary method used to check feature flag state in application code.
Parameters:
- featureName: The name of the feature to evaluate
Returns:
- bool: true if the feature is enabled, false otherwise
- error: An error if the feature flag cannot be found or evaluated
func (*FeatureManager) IsEnabledWithAppContext ¶
func (fm *FeatureManager) IsEnabledWithAppContext(featureName string, appContext any) (bool, error)
IsEnabledWithAppContext determines if a feature flag is enabled for the given context. This version allows passing application-specific context for conditional evaluation.
Parameters:
- featureName: The name of the feature to evaluate
- appContext: An optional context object for contextual evaluation
Returns:
- bool: true if the feature is enabled, false otherwise
- error: An error if the feature flag cannot be found or evaluated
type GroupAllocation ¶
type GroupAllocation struct {
// Variant is the name of the variant to use
Variant string `json:"variant"`
// Groups is the collection of group IDs to apply this variant to
Groups []string `json:"groups"`
}
GroupAllocation assigns a variant to specific user groups
type Options ¶
type Options struct {
// Filters is a list of custom feature filters that will be used during feature flag evaluation.
// Each filter must implement the FeatureFilter interface.
Filters []FeatureFilter
}
Options configures the behavior of the FeatureManager.
type PercentileAllocation ¶
type PercentileAllocation struct {
// Variant is the name of the variant to use
Variant string `json:"variant"`
// From is the lower end of the percentage range (0-100)
From float64 `json:"from"`
// To is the upper end of the percentage range (0-100)
To float64 `json:"to"`
}
PercentileAllocation assigns a variant to a percentage range of users
type RequirementType ¶
type RequirementType string
const ( // RequirementTypeAny indicates that any of the filters must be satisfied RequirementTypeAny RequirementType = "Any" // RequirementTypeAll indicates that all filters must be satisfied RequirementTypeAll RequirementType = "All" )
type StatusOverride ¶
type StatusOverride string
const ( // StatusOverrideNone indicates no override StatusOverrideNone StatusOverride = "None" // StatusOverrideEnabled indicates the feature is enabled StatusOverrideEnabled StatusOverride = "Enabled" // StatusOverrideDisabled indicates the feature is disabled StatusOverrideDisabled StatusOverride = "Disabled" )
type TargetingAudience ¶
type TargetingAudience struct {
DefaultRolloutPercentage float64
Users []string
Groups []TargetingGroup
Exclusion *TargetingExclusion
}
TargetingAudience defines the targeting configuration for feature rollout
type TargetingContext ¶
type TargetingContext struct {
// UserID is the identifier for targeting specific users
UserID string
// Groups are the groups the user belongs to for group targeting
Groups []string
}
TargetingContext provides user-specific information for feature flag targeting. This is used to determine if a feature should be enabled for a specific user or to select the appropriate variant for a user.
type TargetingExclusion ¶
TargetingExclusion defines users and groups explicitly excluded from targeting
type TargetingFilter ¶
type TargetingFilter struct{}
func (*TargetingFilter) Evaluate ¶
func (t *TargetingFilter) Evaluate(evalCtx FeatureFilterEvaluationContext, appCtx any) (bool, error)
func (*TargetingFilter) Name ¶
func (t *TargetingFilter) Name() string
type TargetingFilterParameters ¶
type TargetingFilterParameters struct {
Audience TargetingAudience
}
TargetingFilterParameters defines the parameters for the targeting filter
type TargetingGroup ¶
TargetingGroup defines a named group with a specific rollout percentage
type Telemetry ¶
type Telemetry struct {
// Enabled indicates if telemetry is enabled for this feature
Enabled bool `json:"enabled,omitempty"`
// Metadata contains additional data to include with telemetry
Metadata map[string]string `json:"metadata,omitempty"`
}
Telemetry contains options for feature flag telemetry
type TimeWindowFilter ¶
type TimeWindowFilter struct{}
func (*TimeWindowFilter) Evaluate ¶
func (t *TimeWindowFilter) Evaluate(evalCtx FeatureFilterEvaluationContext, appContext any) (bool, error)
func (*TimeWindowFilter) Name ¶
func (t *TimeWindowFilter) Name() string
type UserAllocation ¶
type UserAllocation struct {
// Variant is the name of the variant to use
Variant string `json:"variant"`
// Users is the collection of user IDs to apply this variant to
Users []string `json:"users"`
}
UserAllocation assigns a variant to specific users
type Variant ¶ added in v1.1.0
type Variant struct {
// Name uniquely identifies this variant
Name string
// ConfigurationValue holds the value for this variant
ConfigurationValue any
}
Variant represents a feature configuration variant. Variants allow different configurations or implementations of a feature to be assigned to different users.
type VariantAllocation ¶
type VariantAllocation struct {
// DefaultWhenDisabled specifies which variant to use when feature is disabled
DefaultWhenDisabled string `json:"default_when_disabled,omitempty"`
// DefaultWhenEnabled specifies which variant to use when feature is enabled
DefaultWhenEnabled string `json:"default_when_enabled,omitempty"`
// User defines variant assignments for specific users
User []UserAllocation `json:"user,omitempty"`
// Group defines variant assignments for user groups
Group []GroupAllocation `json:"group,omitempty"`
// Percentile defines variant assignments by percentage ranges
Percentile []PercentileAllocation `json:"percentile,omitempty"`
// Seed is used to ensure consistent percentile calculations across features
Seed string `json:"seed,omitempty"`
}
VariantAllocation defines rules for assigning variants to users
type VariantAssignmentReason ¶
type VariantAssignmentReason string
VariantAssignmentReason represents the reason a variant was assigned
const ( // VariantAssignmentReasonNone indicates no specific reason for variant assignment VariantAssignmentReasonNone VariantAssignmentReason = "None" // VariantAssignmentReasonDefaultWhenDisabled indicates the variant was assigned because it's the default for disabled features VariantAssignmentReasonDefaultWhenDisabled VariantAssignmentReason = "DefaultWhenDisabled" // VariantAssignmentReasonDefaultWhenEnabled indicates the variant was assigned because it's the default for enabled features VariantAssignmentReasonDefaultWhenEnabled VariantAssignmentReason = "DefaultWhenEnabled" // VariantAssignmentReasonUser indicates the variant was assigned based on the user's ID VariantAssignmentReasonUser VariantAssignmentReason = "User" // VariantAssignmentReasonGroup indicates the variant was assigned based on the user's group VariantAssignmentReasonGroup VariantAssignmentReason = "Group" // VariantAssignmentReasonPercentile indicates the variant was assigned based on percentile calculations VariantAssignmentReasonPercentile VariantAssignmentReason = "Percentile" )
type VariantDefinition ¶
type VariantDefinition struct {
// Name uniquely identifies this variant
Name string `json:"name"`
// ConfigurationValue holds the value for this variant
ConfigurationValue any `json:"configuration_value,omitempty"`
// StatusOverride overrides the enabled state of the feature when this variant is assigned
// Values: "None", "Enabled", "Disabled"
StatusOverride StatusOverride `json:"status_override,omitempty"`
}
VariantDefinition represents a feature configuration variant