eval

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LegacyFractionEvaluationName = "fractionalEvaluation"
	LegacyFractionEvaluationLink = "https://flagd.dev/concepts/#migrating-from-legacy-fractionalevaluation"
)
View Source
const (
	StartsWithEvaluationName = "starts_with"
	EndsWithEvaluationName   = "ends_with"
)
View Source
const (
	Disabled = "DISABLED"
)
View Source
const FractionEvaluationName = "fractional"
View Source
const (
	SelectorMetadataKey = "scope"
)
View Source
const SemVerEvaluationName = "sem_ver"

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyValue

type AnyValue struct {
	Value    interface{}
	Variant  string
	Reason   string
	FlagKey  string
	Metadata map[string]interface{}
	Error    error
}

func NewAnyValue

func NewAnyValue(
	value interface{}, variant string, reason string, flagKey string, metadata map[string]interface{},
	err error,
) AnyValue

type Evaluators

type Evaluators struct {
	Evaluators map[string]json.RawMessage `json:"$evaluators"`
}

type Flags

type Flags struct {
	Flags map[string]model.Flag `json:"flags"`
}

type FractionalEvaluator added in v0.5.4

type FractionalEvaluator struct {
	Logger *logger.Logger
}

func NewFractionalEvaluator added in v0.5.4

func NewFractionalEvaluator(logger *logger.Logger) *FractionalEvaluator

func (*FractionalEvaluator) FractionalEvaluation added in v0.5.4

func (fe *FractionalEvaluator) FractionalEvaluation(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 JSONEvaluator

type JSONEvaluator struct {
	Logger *logger.Logger
	// contains filtered or unexported fields
}

func NewJSONEvaluator

func NewJSONEvaluator(logger *logger.Logger, s *store.Flags, opts ...JSONEvaluatorOption) *JSONEvaluator

func (*JSONEvaluator) GetState

func (je *JSONEvaluator) GetState() (string, error)

func (*JSONEvaluator) ResolveAllValues

func (je *JSONEvaluator) ResolveAllValues(ctx context.Context, reqID string, context map[string]any) []AnyValue

func (*JSONEvaluator) ResolveBooleanValue

func (je *JSONEvaluator) ResolveBooleanValue(
	ctx context.Context, reqID string, flagKey string, context map[string]any) (
	value bool,
	variant string,
	reason string,
	metadata map[string]interface{},
	err error,
)

func (*JSONEvaluator) ResolveFloatValue

func (je *JSONEvaluator) ResolveFloatValue(
	ctx context.Context, reqID string, flagKey string, context map[string]any) (
	value float64,
	variant string,
	reason string,
	metadata map[string]interface{},
	err error,
)

func (*JSONEvaluator) ResolveIntValue

func (je *JSONEvaluator) ResolveIntValue(ctx context.Context, reqID string, flagKey string, context map[string]any) (
	value int64,
	variant string,
	reason string,
	metadata map[string]interface{},
	err error,
)

func (*JSONEvaluator) ResolveObjectValue

func (je *JSONEvaluator) 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,
)

func (*JSONEvaluator) ResolveStringValue

func (je *JSONEvaluator) ResolveStringValue(
	ctx context.Context, reqID string, flagKey string, context map[string]any) (
	value string,
	variant string,
	reason string,
	metadata map[string]interface{},
	err error,
)

func (*JSONEvaluator) SetState

func (je *JSONEvaluator) SetState(payload sync.DataSync) (map[string]interface{}, bool, error)

type JSONEvaluatorOption added in v0.5.4

type JSONEvaluatorOption func(je *JSONEvaluator)

func WithEvaluator added in v0.5.4

func WithEvaluator(name string, evalFunc func(interface{}, interface{}) interface{}) JSONEvaluatorOption

type LegacyFractionalEvaluator deprecated added in v0.6.4

type LegacyFractionalEvaluator struct {
	Logger *logger.Logger
}

Deprecated: LegacyFractionalEvaluator is deprecated. This will be removed prior to v1 release.

func NewLegacyFractionalEvaluator added in v0.6.4

func NewLegacyFractionalEvaluator(logger *logger.Logger) *LegacyFractionalEvaluator

func (*LegacyFractionalEvaluator) LegacyFractionalEvaluation added in v0.6.4

func (fe *LegacyFractionalEvaluator) LegacyFractionalEvaluation(values, data interface{}) interface{}

type SemVerComparisonEvaluator added in v0.5.4

type SemVerComparisonEvaluator struct {
	Logger *logger.Logger
}

func NewSemVerComparisonEvaluator added in v0.5.4

func NewSemVerComparisonEvaluator(log *logger.Logger) *SemVerComparisonEvaluator

func (*SemVerComparisonEvaluator) SemVerEvaluation added in v0.5.4

func (je *SemVerComparisonEvaluator) 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 added in v0.5.4

type SemVerOperator string
const (
	Equals         SemVerOperator = "="
	NotEqual       SemVerOperator = "!="
	Less           SemVerOperator = "<"
	LessOrEqual    SemVerOperator = "<="
	GreaterOrEqual SemVerOperator = ">="
	Greater        SemVerOperator = ">"
	MatchMajor     SemVerOperator = "^"
	MatchMinor     SemVerOperator = "~"
)

type StringComparisonEvaluator added in v0.5.4

type StringComparisonEvaluator struct {
	Logger *logger.Logger
}

func NewStringComparisonEvaluator added in v0.5.4

func NewStringComparisonEvaluator(log *logger.Logger) *StringComparisonEvaluator

func (StringComparisonEvaluator) EndsWithEvaluation added in v0.5.4

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 added in v0.5.4

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

Directories

Path Synopsis
Package evalmock is a generated GoMock package.
Package evalmock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL