Documentation ¶
Index ¶
- Constants
- type AnyValue
- type Evaluators
- type Flags
- type Fractional
- type IEvaluator
- type IResolver
- type JSON
- type JSONEvaluatorOption
- type LegacyFractionaldeprecated
- type Resolver
- func (je *Resolver) ResolveAllValues(ctx context.Context, reqID string, context map[string]any) ([]AnyValue, error)
- func (je *Resolver) ResolveAsAnyValue(ctx context.Context, reqID string, flagKey string, context map[string]any) AnyValue
- func (je *Resolver) ResolveBooleanValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value bool, variant string, reason string, metadata map[string]interface{}, ...)
- func (je *Resolver) ResolveFloatValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value float64, variant string, reason string, metadata map[string]interface{}, ...)
- func (je *Resolver) ResolveIntValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value int64, variant string, reason string, metadata map[string]interface{}, ...)
- func (je *Resolver) ResolveObjectValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value map[string]any, variant string, reason string, ...)
- func (je *Resolver) ResolveStringValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value string, variant string, reason string, metadata map[string]interface{}, ...)
- type SemVerComparison
- type SemVerOperator
- type StringComparisonEvaluator
Constants ¶
const ( SelectorMetadataKey = "scope" Disabled = "DISABLED" )
const ( LegacyFractionEvaluationName = "fractionalEvaluation" LegacyFractionEvaluationLink = "https://flagd.dev/concepts/#migrating-from-legacy-fractionalevaluation" )
const ( StartsWithEvaluationName = "starts_with" EndsWithEvaluationName = "ends_with" )
const FractionEvaluationName = "fractional"
const SemVerEvaluationName = "sem_ver"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnyValue ¶
type Evaluators ¶
type Evaluators struct {
Evaluators map[string]json.RawMessage `json:"$evaluators"`
}
type Fractional ¶
func NewFractional ¶
func NewFractional(logger *logger.Logger) *Fractional
func (*Fractional) Evaluate ¶
func (fe *Fractional) Evaluate(values, data any) any
type IEvaluator ¶
type IEvaluator interface { GetState() (string, error) SetState(payload sync.DataSync) (map[string]interface{}, bool, error) IResolver }
IEvaluator is an extension of IResolver, allowing storage updates and retrievals
type IResolver ¶ added in v0.9.0
type IResolver interface { ResolveBooleanValue( ctx context.Context, reqID string, flagKey string, context map[string]any) (value bool, variant string, reason string, metadata map[string]interface{}, err error) ResolveStringValue( ctx context.Context, reqID string, flagKey string, context map[string]any) ( value string, variant string, reason string, metadata map[string]interface{}, err error) ResolveIntValue( ctx context.Context, reqID string, flagKey string, context map[string]any) ( value int64, variant string, reason string, metadata map[string]interface{}, err error) ResolveFloatValue( ctx context.Context, reqID string, flagKey string, context map[string]any) ( value float64, variant string, reason string, metadata map[string]interface{}, err error) ResolveObjectValue( ctx context.Context, reqID string, flagKey string, context map[string]any) ( value map[string]any, variant string, reason string, metadata map[string]interface{}, err error) ResolveAsAnyValue( ctx context.Context, reqID string, flagKey string, context map[string]any) AnyValue ResolveAllValues( ctx context.Context, reqID string, context map[string]any) (values []AnyValue, err error) }
IResolver focuses on resolving of the known flags
type JSONEvaluatorOption ¶
type JSONEvaluatorOption func(je *JSON)
func WithEvaluator ¶
func WithEvaluator(name string, evalFunc func(interface{}, interface{}) interface{}) JSONEvaluatorOption
Deprecated - this will be remove in the next release
type LegacyFractional
deprecated
Deprecated: LegacyFractional is deprecated. This will be removed prior to v1 release.
func NewLegacyFractional ¶
func NewLegacyFractional(logger *logger.Logger) *LegacyFractional
func (*LegacyFractional) LegacyFractionalEvaluation ¶
func (fe *LegacyFractional) LegacyFractionalEvaluation(values, data interface{}) interface{}
type Resolver ¶ added in v0.9.0
Resolver implementation for flagd flags. This resolver should be kept reusable, hence must interact with interfaces.
func NewResolver ¶ added in v0.9.0
func (*Resolver) ResolveAllValues ¶ added in v0.9.0
func (*Resolver) ResolveAsAnyValue ¶ added in v0.9.0
func (*Resolver) ResolveBooleanValue ¶ added in v0.9.0
func (*Resolver) ResolveFloatValue ¶ added in v0.9.0
func (*Resolver) ResolveIntValue ¶ added in v0.9.0
func (*Resolver) ResolveObjectValue ¶ added in v0.9.0
type SemVerComparison ¶
func NewSemVerComparison ¶
func NewSemVerComparison(log *logger.Logger) *SemVerComparison
func (*SemVerComparison) SemVerEvaluation ¶
func (je *SemVerComparison) SemVerEvaluation(values, _ interface{}) interface{}
SemVerEvaluation checks if the given property matches a semantic versioning condition. It returns 'true', if the value of the given property meets the condition, 'false' if not. As an example, it can be used in the following way inside an 'if' evaluation:
{ "if": [ { "sem_ver": [{"var": "version"}, ">=", "1.0.0"] }, "red", null ] }
This rule can be applied to the following data object, where the evaluation will resolve to 'true':
{ "version": "2.0.0" }
Note that the 'sem_ver' evaluation rule must contain exactly three items: 1. Target property: this needs which both resolve to a semantic versioning string 2. Operator: One of the following: '=', '!=', '>', '<', '>=', '<=', '~', '^' 3. Target value: this needs which both resolve to a semantic versioning string
type SemVerOperator ¶
type SemVerOperator string
const ( Equals SemVerOperator = "=" NotEqual SemVerOperator = "!=" Less SemVerOperator = "<" LessOrEqual SemVerOperator = "<=" GreaterOrEqual SemVerOperator = ">=" Greater SemVerOperator = ">" MatchMajor SemVerOperator = "^" MatchMinor SemVerOperator = "~" )
type StringComparisonEvaluator ¶
func NewStringComparisonEvaluator ¶
func NewStringComparisonEvaluator(log *logger.Logger) *StringComparisonEvaluator
func (*StringComparisonEvaluator) EndsWithEvaluation ¶
func (sce *StringComparisonEvaluator) EndsWithEvaluation(values, _ interface{}) interface{}
EndsWithEvaluation checks if the given property ends with a certain prefix. It returns 'true', if the value of the given property starts with the prefix, 'false' if not. As an example, it can be used in the following way inside an 'if' evaluation:
{ "if": [ { "ends_with": [{"var": "email"}, "faas.com"] }, "red", null ] }
This rule can be applied to the following data object, where the evaluation will resolve to 'true':
{ "email": "user@faas.com" }
Note that the 'ends_with' evaluation rule must contain exactly two items, which both resolve to a string value
func (*StringComparisonEvaluator) StartsWithEvaluation ¶
func (sce *StringComparisonEvaluator) StartsWithEvaluation(values, _ interface{}) interface{}
StartsWithEvaluation checks if the given property starts with a certain prefix. It returns 'true', if the value of the given property starts with the prefix, 'false' if not. As an example, it can be used in the following way inside an 'if' evaluation:
{ "if": [ { "starts_with": [{"var": "email"}, "user@faas"] }, "red", null ] }
This rule can be applied to the following data object, where the evaluation will resolve to 'true':
{ "email": "user@faas.com" }
Note that the 'starts_with' evaluation rule must contain exactly two items, which both resolve to a string value