evaluator

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 26 Imported by: 4

Documentation

Index

Constants

View Source
const (
	SelectorMetadataKey = "scope"

	Disabled = "DISABLED"
)
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 FractionEvaluationName = "fractional"
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 Fractional

type Fractional struct {
	Logger *logger.Logger
}

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 JSON

type JSON struct {
	Logger *logger.Logger

	Resolver
	// contains filtered or unexported fields
}

JSON evaluator

func NewJSON

func NewJSON(logger *logger.Logger, s *store.Flags, opts ...JSONEvaluatorOption) *JSON

func (*JSON) GetState

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

func (*JSON) SetState

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

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

type LegacyFractional struct {
	Logger *logger.Logger
}

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

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

Resolver implementation for flagd flags. This resolver should be kept reusable, hence must interact with interfaces.

func NewResolver added in v0.9.0

func NewResolver(store store.IStore, logger *logger.Logger, jsonEvalTracer trace.Tracer) Resolver

func (*Resolver) ResolveAllValues added in v0.9.0

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

func (*Resolver) ResolveAsAnyValue added in v0.9.0

func (je *Resolver) ResolveAsAnyValue(
	ctx context.Context,
	reqID string,
	flagKey string,
	context map[string]any,
) AnyValue

func (*Resolver) ResolveBooleanValue added in v0.9.0

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{},
	err error,
)

func (*Resolver) ResolveFloatValue added in v0.9.0

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{},
	err error,
)

func (*Resolver) ResolveIntValue added in v0.9.0

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{},
	err error,
)

func (*Resolver) ResolveObjectValue added in v0.9.0

func (je *Resolver) 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 (*Resolver) ResolveStringValue added in v0.9.0

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{},
	err error,
)

type SemVerComparison

type SemVerComparison struct {
	Logger *logger.Logger
}

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

type StringComparisonEvaluator struct {
	Logger *logger.Logger
}

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

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