Documentation ¶
Index ¶
- Constants
- type AnyValue
- type Evaluators
- type Flags
- type Fractional
- type IEvaluator
- type JSON
- func (je *JSON) GetState() (string, error)
- func (je *JSON) ResolveAllValues(ctx context.Context, reqID string, context map[string]any) []AnyValue
- func (je *JSON) ResolveBooleanValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value bool, variant string, reason string, metadata map[string]interface{}, ...)
- func (je *JSON) ResolveFloatValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value float64, variant string, reason string, metadata map[string]interface{}, ...)
- func (je *JSON) ResolveIntValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value int64, variant string, reason string, metadata map[string]interface{}, ...)
- func (je *JSON) ResolveObjectValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value map[string]any, variant string, reason string, ...)
- func (je *JSON) ResolveStringValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (value string, variant string, reason string, metadata map[string]interface{}, ...)
- func (je *JSON) SetState(payload sync.DataSync) (map[string]interface{}, bool, error)
- type JSONEvaluatorOption
- type LegacyFractionaldeprecated
- type SemVerComparison
- type SemVerOperator
- type StringComparisonEvaluator
Constants ¶
const ( LegacyFractionEvaluationName = "fractionalEvaluation" LegacyFractionEvaluationLink = "https://flagd.dev/concepts/#migrating-from-legacy-fractionalevaluation" )
const ( StartsWithEvaluationName = "starts_with" EndsWithEvaluationName = "ends_with" )
const (
Disabled = "DISABLED"
)
const FractionEvaluationName = "fractional"
const (
SelectorMetadataKey = "scope"
)
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) 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) ResolveAllValues( ctx context.Context, reqID string, context map[string]any) (values []AnyValue) }
IEvaluator implementations store the state of the flags, do parsing and validation of the flag state and evaluate flags in response to handlers.
type JSON ¶
func (*JSON) ResolveAllValues ¶
func (*JSON) ResolveBooleanValue ¶
func (*JSON) ResolveFloatValue ¶
func (*JSON) ResolveIntValue ¶
func (*JSON) ResolveObjectValue ¶
func (*JSON) ResolveStringValue ¶
type JSONEvaluatorOption ¶
type JSONEvaluatorOption func(je *JSON)
func WithEvaluator ¶
func WithEvaluator(name string, evalFunc func(interface{}, interface{}) interface{}) JSONEvaluatorOption
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 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