Documentation
¶
Index ¶
- Constants
- func DateFromContextOrDefault(ctx ffcontext.Context, defaultDate time.Time) time.Time
- func MergeSetOfRules(initialRules, updates []Rule) *[]Rule
- type Context
- type ErrorCode
- type ExperimentationRollout
- type Flag
- type InternalFlag
- func (f *InternalFlag) GetBucketingKey() string
- func (f *InternalFlag) GetBucketingKeyValue(ctx ffcontext.Context) (string, error)
- func (f *InternalFlag) GetDefaultRule() *Rule
- func (f *InternalFlag) GetMetadata() map[string]any
- func (f *InternalFlag) GetRuleIndexByName(name string) *int
- func (f *InternalFlag) GetRules() []Rule
- func (f *InternalFlag) GetVariationValue(name string) any
- func (f *InternalFlag) GetVariations() map[string]*any
- func (f *InternalFlag) GetVersion() string
- func (f *InternalFlag) IsDisable() bool
- func (f *InternalFlag) IsTrackEvents() bool
- func (f *InternalFlag) IsValid() error
- func (f *InternalFlag) RequiresBucketing() bool
- func (f *InternalFlag) Value(flagName string, evaluationCtx ffcontext.Context, flagContext Context) (any, ResolutionDetails)
- type ProgressiveRollout
- type ProgressiveRolloutStep
- type QueryFormat
- type ResolutionDetails
- type ResolutionReason
- type Rollout
- type Rule
- func (r *Rule) Evaluate(key string, ctx ffcontext.Context, flagName string, isDefault bool) (string, error)
- func (r *Rule) EvaluatePercentageRollout(key, flagName string) (string, error)
- func (r *Rule) EvaluateProgressiveRollout(key string, flagName string, evaluationDate time.Time) (string, error)
- func (r *Rule) GetName() string
- func (r *Rule) GetPercentages() map[string]float64
- func (r *Rule) GetProgressiveRollout() ProgressiveRollout
- func (r *Rule) GetQuery() string
- func (r *Rule) GetQueryFormat() QueryFormat
- func (r *Rule) GetTrimmedQuery() string
- func (r *Rule) GetVariationResult() string
- func (r *Rule) IsDisable() bool
- func (r *Rule) IsDynamic() bool
- func (r *Rule) IsValid(defaultRule bool, variations map[string]*any) error
- func (r *Rule) MergeRules(updatedRule Rule)
- func (r *Rule) RequiresBucketing() bool
- type ScheduledStep
Constants ¶
const (
PercentageMultiplier = float64(1000)
)
const VariationSDKDefault string = "SdkDefault"
Variables ¶
This section is empty.
Functions ¶
func MergeSetOfRules ¶
MergeSetOfRules is taking a collection of rules and merge it with the updates from a schedule steps. If you want to edit a rule this rule should have a name already to be able to target the updates to the right place.
Types ¶
type Context ¶
type Context struct {
// EvaluationContextEnrichment will be merged with the evaluation context sent during the evaluation.
// It is useful to add common attributes to all the evaluation, such as a server version, environment, ...
//
// All those fields will be included in the custom attributes of the evaluation context,
// if in the evaluation context you have a field with the same name, it will override the common one.
// Default: nil
EvaluationContextEnrichment map[string]any `json:"evaluationContextEnrichment,omitempty"`
// DefaultSdkValue is the default value of the SDK when calling the variation.
DefaultSdkValue any `json:"defaultSdkValue,omitempty"`
}
func (*Context) AddIntoEvaluationContextEnrichment ¶
AddIntoEvaluationContextEnrichment adds a key and value to the evaluation context enrichment.
type ErrorCode ¶
type ErrorCode = string
ErrorCode is an enum following the open-feature specs about error code.
const ( // Proposed in the open-feature specs ErrorCodeProviderNotReady ErrorCode = "PROVIDER_NOT_READY" ErrorCodeFlagNotFound ErrorCode = "FLAG_NOT_FOUND" ErrorCodeParseError ErrorCode = "PARSE_ERROR" ErrorCodeTypeMismatch ErrorCode = "TYPE_MISMATCH" ErrorCodeGeneral ErrorCode = "GENERAL" ErrorCodeInvalidContext ErrorCode = "INVALID_CONTEXT" ErrorCodeTargetingKeyMissing ErrorCode = "TARGETING_KEY_MISSING" // ErrorFlagConfiguration is returned when we were not able to use the flag because of a misconfiguration ErrorFlagConfiguration ErrorCode = "FLAG_CONFIG" )
type ExperimentationRollout ¶
type ExperimentationRollout struct {
// Start is the starting time of the experimentation
Start *time.Time `json:"start,omitempty" yaml:"start,omitempty" toml:"start,omitempty"`
// End is the ending time of the experimentation
End *time.Time `json:"end,omitempty" yaml:"end,omitempty" toml:"end,omitempty"`
}
type Flag ¶
type Flag interface {
// Value is returning the Value associate to the flag
Value(
flagName string,
evaluationContext ffcontext.Context,
flagContext Context,
) (any, ResolutionDetails)
// GetVersion is the getter for the field Version
// Default: 0.0
GetVersion() string
// IsTrackEvents is the getter of the field TrackEvents
// Default: true
IsTrackEvents() bool
// IsDisable is the getter for the field Disable
// Default: false
IsDisable() bool
// GetVariationValue return the value of variation from his name
GetVariationValue(name string) any
// GetMetadata return the metadata associated to the flag
GetMetadata() map[string]any
}
type InternalFlag ¶
type InternalFlag struct {
// Variations are all the variations available for this flag. You can have as many variation as needed.
Variations *map[string]*any `json:"variations,omitempty" yaml:"variations,omitempty" toml:"variations,omitempty"` // nolint:lll
// Rules is the list of Rule for this flag.
// This an optional field.
Rules *[]Rule `json:"targeting,omitempty" yaml:"targeting,omitempty" toml:"targeting,omitempty"`
// BucketingKey defines a source for a dynamic targeting key
BucketingKey *string `json:"bucketingKey,omitempty" yaml:"bucketingKey,omitempty" toml:"bucketingKey,omitempty"`
// DefaultRule is the originalRule applied after checking that any other rules
// matched the user.
DefaultRule *Rule `json:"defaultRule,omitempty" yaml:"defaultRule,omitempty" toml:"defaultRule,omitempty"`
// Experimentation is your struct to configure an experimentation, it will allow you to configure a start date and
// an end date for your flag.
// When the experimentation is not running, the flag will serve the default value.
Experimentation *ExperimentationRollout `json:"experimentation,omitempty" yaml:"experimentation,omitempty" toml:"experimentation,omitempty"` // nolint: lll
// Scheduled is your struct to configure an update on some fields of your flag over time.
// You can add several steps that updates the flag, this is typically used if you want to gradually add more user
// in your flag.
Scheduled *[]ScheduledStep `json:"scheduledRollout,omitempty" yaml:"scheduledRollout,omitempty" toml:"scheduledRollout,omitempty"` // nolint: lll
// TrackEvents is false if you don't want to export the data in your data exporter.
// Default value is true
TrackEvents *bool `json:"trackEvents,omitempty" yaml:"trackEvents,omitempty" toml:"trackEvents,omitempty"`
// Disable is true if the flag is disabled.
Disable *bool `json:"disable,omitempty" yaml:"disable,omitempty" toml:"disable,omitempty"`
// Version (optional) This field contains the version of the flag.
// The version is manually managed when you configure your flags, and it is used to display the information
// in the notifications and data collection.
Version *string `json:"version,omitempty" yaml:"version,omitempty" toml:"version,omitempty"`
// Metadata is a field containing information about your flag such as an issue tracker link, a description, etc ...
Metadata *map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty" toml:"metadata,omitempty"`
}
InternalFlag is the internal representation of a flag when using go-feature-flag. All the flags in your configuration files can have different format but will be converted into an InternalFlag to be used in the library.
func (*InternalFlag) GetBucketingKey ¶
func (f *InternalFlag) GetBucketingKey() string
GetBucketingKey return the name of the custom bucketing key if we are using one.
func (*InternalFlag) GetBucketingKeyValue ¶
func (f *InternalFlag) GetBucketingKeyValue(ctx ffcontext.Context) (string, error)
GetBucketingKeyValue return the value of the bucketing key from the context If requiresBucketing is false, it allows empty keys for flags that don't need them
func (*InternalFlag) GetDefaultRule ¶
func (f *InternalFlag) GetDefaultRule() *Rule
GetDefaultRule is the getter of the field DefaultRule
func (*InternalFlag) GetMetadata ¶
func (f *InternalFlag) GetMetadata() map[string]any
GetMetadata return the metadata associated to the flag
func (*InternalFlag) GetRuleIndexByName ¶
func (f *InternalFlag) GetRuleIndexByName(name string) *int
func (*InternalFlag) GetRules ¶
func (f *InternalFlag) GetRules() []Rule
func (*InternalFlag) GetVariationValue ¶
func (f *InternalFlag) GetVariationValue(name string) any
GetVariationValue return the value of variation from his name
func (*InternalFlag) GetVariations ¶
func (f *InternalFlag) GetVariations() map[string]*any
GetVariations is the getter of the field Variations
func (*InternalFlag) GetVersion ¶
func (f *InternalFlag) GetVersion() string
GetVersion is the getter for the field Version
func (*InternalFlag) IsDisable ¶
func (f *InternalFlag) IsDisable() bool
IsDisable is the getter for the field Disable
func (*InternalFlag) IsTrackEvents ¶
func (f *InternalFlag) IsTrackEvents() bool
IsTrackEvents is the getter of the field TrackEvents
func (*InternalFlag) IsValid ¶
func (f *InternalFlag) IsValid() error
IsValid is checking if the current flag is valid.
func (*InternalFlag) RequiresBucketing ¶ added in v0.3.0
func (f *InternalFlag) RequiresBucketing() bool
RequiresBucketing checks if the flag requires a bucketing key for evaluation A flag requires bucketing if it has percentage-based rules or progressive rollouts, including those introduced by scheduled rollout steps
func (*InternalFlag) Value ¶
func (f *InternalFlag) Value( flagName string, evaluationCtx ffcontext.Context, flagContext Context, ) (any, ResolutionDetails)
Value is returning the Value associate to the flag
type ProgressiveRollout ¶
type ProgressiveRollout struct {
// Initial contains a description of the initial state of the rollout.
Initial *ProgressiveRolloutStep `` // nolint: lll
/* 164-byte string literal not displayed */
// End contains what describes the end status of the rollout.
End *ProgressiveRolloutStep `` // nolint: lll
/* 148-byte string literal not displayed */
}
ProgressiveRollout represents how to progressively roll out a originalRule.
type ProgressiveRolloutStep ¶
type ProgressiveRolloutStep struct {
// Variation - name of the variation for this step
Variation *string `` // nolint: lll
/* 162-byte string literal not displayed */
// Percentage is the percentage (initial or end) for the progressive rollout
Percentage *float64 `` // nolint: lll
/* 195-byte string literal not displayed */
// Date is the time it starts or ends.
Date *time.Time `` // nolint: lll
/* 146-byte string literal not displayed */
}
ProgressiveRolloutStep define a progressive rollout step (initial and end)
type QueryFormat ¶
type QueryFormat = string
const ( NikunjyQueryFormat QueryFormat = "nikunjy" JSONLogicQueryFormat QueryFormat = "jsonlogic" )
type ResolutionDetails ¶
type ResolutionDetails struct {
// Variant indicates the name of the variant used when evaluating the flag
Variant string
// Reason indicates the reason of the decision
Reason ResolutionReason
// ErrorCode indicates the error code for this evaluation
ErrorCode ErrorCode
// ErrorMessage gives more information about the error
ErrorMessage string
// RuleIndex indicates which rules applied
RuleIndex *int
// RuleName (optional) is the name of the associated rule if we have one
RuleName *string
// Cacheable is set to true if an SDK/provider can cache the value locally.
Cacheable bool
// Metadata is a field containing information about your flag such as an issue tracker link, a description, etc ...
Metadata map[string]any
}
ResolutionDetails is the object used to manipulate the data internally, it allows to retrieve the details of your evaluation.
type ResolutionReason ¶
type ResolutionReason = string
ResolutionReason is an enum following the open-feature specs about resolution reasons.
const ( // ReasonTargetingMatch The resolved value was the result of a dynamic evaluation, // such as a rule or specific user-targeting. // ex: serve variation A if username is Thomas ReasonTargetingMatch ResolutionReason = "TARGETING_MATCH" // ReasonTargetingMatchSplit The resolved value was the result of a dynamic evaluation, // that is serving a percentage. // ex: serve variation A to 10% of users with the username Thomas ReasonTargetingMatchSplit ResolutionReason = "TARGETING_MATCH_SPLIT" // ReasonSplit The resolved value was the result of pseudorandom assignment. // ex: serve variation A to 10% of all the users. ReasonSplit ResolutionReason = "SPLIT" // ReasonDisabled Indicates that the feature flag is disabled ReasonDisabled ResolutionReason = "DISABLED" // ReasonDefault The resolved value was the result of the flag being disabled in the management system. ReasonDefault ResolutionReason = "DEFAULT" // ReasonStatic Indicates that the feature flag evaluated to a // static value, for example, the default value for the flag // // Note: Typically means that no dynamic evaluation has been // executed for the feature flag ReasonStatic ResolutionReason = "STATIC" // ReasonUnknown Indicates an unknown issue occurred during evaluation ReasonUnknown ResolutionReason = "UNKNOWN" // ReasonError Indicates that an error occurred during evaluation // Note: The `errorCode`-field contains the details of this error ReasonError ResolutionReason = "ERROR" // ReasonOffline Indicates that GO Feature Flag is currently evaluating in offline mode. ReasonOffline ResolutionReason = "OFFLINE" )
type Rollout ¶
type Rollout struct {
// Experimentation is your struct to configure an experimentation, it will allow you to configure a start date and
// an end date for your flag.
// When the experimentation is not running, the flag will serve the default value.
Experimentation *ExperimentationRollout `json:"experimentation,omitempty" yaml:"experimentation,omitempty" toml:"experimentation,omitempty"` // nolint: lll
// Scheduled is your struct to configure an update on some fields of your flag over time.
// You can add several steps that update the flag, this is typically used if you want to gradually add more user
// in your flag.
Scheduled *[]ScheduledStep `json:"scheduled,omitempty" yaml:"scheduled,omitempty" toml:"scheduled,omitempty"`
}
type Rule ¶
type Rule struct {
// Name is the name of the rule, this field is mandatory if you want
// to update the rule during scheduled rollout
Name *string `` // nolint: lll
/* 212-byte string literal not displayed */
// Query represents the query used to target the audience of the flag.
Query *string `` // nolint: lll
/* 217-byte string literal not displayed */
// VariationResult represents the variation name to use if the rule apply for the user.
// In case we have a percentage field in the config VariationResult is ignored
VariationResult *string `` // nolint: lll
/* 250-byte string literal not displayed */
// Percentages represents the percentage we should give to each variation.
// example: variationA = 10%, variationB = 80%, variationC = 10%
Percentages *map[string]float64 `` // nolint: lll
/* 185-byte string literal not displayed */
// ProgressiveRollout is your struct to configure a progressive rollout deployment of your flag.
// It will allow you to ramp up the percentage of your flag over time.
// You can decide at which percentage you starts with and at what percentage you ends with in your release ramp.
// Before the start date we will serve the initial percentage and, after we will serve the end percentage.
ProgressiveRollout *ProgressiveRollout `` // nolint: lll
/* 214-byte string literal not displayed */
// Disable indicates that this rule is disabled.
Disable *bool `` // nolint: lll
/* 151-byte string literal not displayed */
}
Rule represents a rule applied by the flag.
func (*Rule) Evaluate ¶
func (r *Rule) Evaluate(key string, ctx ffcontext.Context, flagName string, isDefault bool, ) (string, error)
Evaluate is checking if the rule applies to for the user. If yes, it returns the variation you should use for this rule.
func (*Rule) EvaluatePercentageRollout ¶
EvaluatePercentageRollout is evaluating the percentage rollout for the rule.
func (*Rule) EvaluateProgressiveRollout ¶
func (r *Rule) EvaluateProgressiveRollout( key string, flagName string, evaluationDate time.Time, ) (string, error)
EvaluateProgressiveRollout is evaluating the progressive rollout for the rule.
func (*Rule) GetPercentages ¶
func (*Rule) GetProgressiveRollout ¶
func (r *Rule) GetProgressiveRollout() ProgressiveRollout
func (*Rule) GetQueryFormat ¶
func (r *Rule) GetQueryFormat() QueryFormat
GetQueryFormat is returning the format used for the query
func (*Rule) GetTrimmedQuery ¶
GetTrimmedQuery is removing the break lines and return
func (*Rule) GetVariationResult ¶
func (*Rule) IsDynamic ¶
IsDynamic is a function that allows to know if the rule has a dynamic result or not.
func (*Rule) MergeRules ¶
MergeRules is merging 2 rules. It is used when we have to update a rule in a scheduled rollout.
func (*Rule) RequiresBucketing ¶ added in v0.3.0
RequiresBucketing checks if this rule requires a bucketing key for evaluation
type ScheduledStep ¶
type ScheduledStep struct {
InternalFlag `yaml:",inline"`
Date *time.Time `yaml:"date,omitempty" json:"date,omitempty" toml:"date,omitempty"`
}
ScheduledStep is one change of the flag.