evaluation

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: Apache-2.0 Imports: 9 Imported by: 5

README

SimpleFlags Evaluation Engine


based on harness.io ff evaluation engine

Overview


This is experimental project, do not use it in production and it will not work with harness.io backend

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongTypeAssertion           = errors.New("wrong type assertion")
	ErrTargetAttributeCannotBeEmpty = errors.New("attribute cannot be empty")
	ErrOperatorCannotBeEmpty        = errors.New("operator cannot be empty")
	ErrClauseValuesCannotBeEmpty    = errors.New("clause values cannot be empty")
)
View Source
var (
	// ErrQueryProviderMissing ...
	ErrQueryProviderMissing = errors.New("query field is missing in evaluator")
	// ErrVariationNotFound ...
	ErrVariationNotFound = errors.New("variation not found")
	// ErrEvaluationFlag ...
	ErrEvaluationFlag = errors.New("error while evaluating flag")
)

Functions

func SetLogger

func SetLogger(logger Logger)

Types

type Boolean

type Boolean bool

Boolean type for clause attribute evaluation

func NewBoolean

func NewBoolean(value interface{}) (*Boolean, error)

NewBoolean creates a Boolean instance with the object value

func (Boolean) Contains

func (b Boolean) Contains([]interface{}) bool

Contains always return false

func (Boolean) EndsWith

func (b Boolean) EndsWith([]interface{}) bool

EndsWith always return false

func (Boolean) Equal

func (b Boolean) Equal(value []interface{}) bool

Equal check if the boolean and value are equal

func (Boolean) EqualSensitive

func (b Boolean) EqualSensitive([]interface{}) bool

EqualSensitive always return false

func (Boolean) GreaterThan

func (b Boolean) GreaterThan([]interface{}) bool

GreaterThan always return false

func (Boolean) GreaterThanEqual

func (b Boolean) GreaterThanEqual([]interface{}) bool

GreaterThanEqual always return false

func (Boolean) In

func (b Boolean) In([]interface{}) bool

In always return false

func (Boolean) LessThan

func (b Boolean) LessThan([]interface{}) bool

LessThan always return false

func (Boolean) LessThanEqual

func (b Boolean) LessThanEqual([]interface{}) bool

LessThanEqual always return false

func (Boolean) Match

func (b Boolean) Match([]interface{}) bool

Match always return false

func (Boolean) StartsWith

func (b Boolean) StartsWith([]interface{}) bool

StartsWith always return false

type Clause

type Clause struct {
	Attribute string        `json:"attribute" validate:"required"`
	Operator  string        `json:"operator" validate:"required"`
	Negate    bool          `json:"negate"`
	Values    []interface{} `json:"values" validate:"required"`

} // @name Clause

type Configuration

type Configuration struct {
	Organization  string               `json:"organization"`
	Project       string               `json:"project"`
	Environment   string               `json:"environment"`
	Identifier    string               `json:"identifier"`
	Deprecated    bool                 `json:"deprecated"`
	On            bool                 `json:"on"`
	OffVariation  string               `json:"offVariation"`
	Rules         []ServingRule        `json:"rules"`
	TargetRules   []TargetRule         `json:"targetRules"`
	Prerequisites []Prerequisite       `json:"prerequisites"`
	DefaultServe  Serve                `json:"defaultServe"`
	Variations    map[string]Variation `json:"variations"`
	Version       uint                 `json:"version"`

} // @name Configuration

type Configurations

type Configurations []Configuration // @name Configurations

type DataProvider

type DataProvider interface {
	GetTargetGroup(identifier interface{}) (TargetGroup, error)
	GetFlag(identifier interface{}) (Configuration, error)
}

DataProvider provides methods for segment and flag retrieval

type Distribution

type Distribution struct {
	BucketBy   string              `json:"bucketBy" validate:"required"`
	Variations []WeightedVariation `json:"variations" validate:"required"`

} // @name Distribution

func (Distribution) IsEmpty

func (d Distribution) IsEmpty() bool

type Evaluation

type Evaluation struct {
	Organization string      `json:"organization"`
	Project      string      `json:"project"`
	Environment  string      `json:"environment"`
	Identifier   string      `json:"identifier"`
	Value        interface{} `json:"value"`

} // @name Evaluations

type Evaluations

type Evaluations []Evaluation // @name Evaluations

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator engine evaluates flag from provided query

func NewEvaluator

func NewEvaluator(provider DataProvider) (Evaluator, error)

NewEvaluator constructs evaluator with query instance

func (Evaluator) Evaluate

func (e Evaluator) Evaluate(key interface{}, target *Target) Variation

type Integer

type Integer int64

Integer type for clause attribute evaluation

func NewInteger

func NewInteger(value interface{}) (Integer, error)

NewInteger creates a Integer instance with the object value

func (Integer) Contains

func (n Integer) Contains([]interface{}) bool

Contains always return false

func (Integer) EndsWith

func (n Integer) EndsWith([]interface{}) bool

EndsWith always return false

func (Integer) Equal

func (n Integer) Equal(value []interface{}) bool

Equal check if the number and value are equal

func (Integer) EqualSensitive

func (n Integer) EqualSensitive([]interface{}) bool

EqualSensitive always return false

func (Integer) GreaterThan

func (n Integer) GreaterThan(values []interface{}) bool

GreaterThan checks if the number is greater than the value

func (Integer) GreaterThanEqual

func (n Integer) GreaterThanEqual(values []interface{}) bool

GreaterThanEqual checks if the number is greater or equal than the value

func (Integer) In

func (n Integer) In(values []interface{}) bool

In checks if the number exist in slice of numbers (value)

func (Integer) LessThan

func (n Integer) LessThan(values []interface{}) bool

LessThan checks if the number is less than the value

func (Integer) LessThanEqual

func (n Integer) LessThanEqual(values []interface{}) bool

LessThanEqual checks if the number is less or equal than the value

func (Integer) Match

func (n Integer) Match([]interface{}) bool

Match always return false

func (Integer) StartsWith

func (n Integer) StartsWith([]interface{}) bool

StartsWith always return false

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(template string, args ...interface{})
	Info(args ...interface{})
	Infof(template string, args ...interface{})
	Warn(args ...interface{})
	Warnf(template string, args ...interface{})
	Error(args ...interface{})
	Errorf(template string, args ...interface{})
	Panic(args ...interface{})
	Panicf(template string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(template string, args ...interface{})
}

type Number

type Number float64

Number type for clause attribute evaluation

func NewNumber

func NewNumber(value interface{}) (Number, error)

NewNumber creates a Number instance with the object value

func (Number) Contains

func (n Number) Contains([]interface{}) bool

Contains always return false

func (Number) EndsWith

func (n Number) EndsWith(values []interface{}) bool

EndsWith always return false

func (Number) Equal

func (n Number) Equal(values []interface{}) bool

Equal check if the number and value are equal

func (Number) EqualSensitive

func (n Number) EqualSensitive(values []interface{}) bool

EqualSensitive always return false

func (Number) GreaterThan

func (n Number) GreaterThan(values []interface{}) bool

GreaterThan checks if the number is greater than the value

func (Number) GreaterThanEqual

func (n Number) GreaterThanEqual(values []interface{}) bool

GreaterThanEqual checks if the number is greater or equal than the value

func (Number) In

func (n Number) In(values []interface{}) bool

In checks if the number exist in slice of numbers (value)

func (Number) LessThan

func (n Number) LessThan(values []interface{}) bool

LessThan checks if the number is less than the value

func (Number) LessThanEqual

func (n Number) LessThanEqual(values []interface{}) bool

LessThanEqual checks if the number is less or equal than the value

func (Number) Match

func (n Number) Match(values []interface{}) bool

Match always return false

func (Number) StartsWith

func (n Number) StartsWith(values []interface{}) bool

StartsWith always return false

type Prerequisite

type Prerequisite struct {
	Feature    string   `json:"feature" validate:"required"`
	Variations []string `json:"variations" validate:"required"`

} // @name Prerequisite

type Serve

type Serve struct {
	Distribution *Distribution `json:"distribution,omitempty"`
	Variation    *string       `json:"variation,omitempty"`

} // @name Serve

func (Serve) IsEmpty

func (s Serve) IsEmpty() bool

type ServingRule

type ServingRule struct {
	Priority int      `json:"priority" validate:"required"`
	Clauses  []Clause `json:"clauses"`
	Serve    Serve    `json:"serve"`

} // @name ServingRule

type Slice

type Slice struct {
	// contains filtered or unexported fields
}

Slice type for clause attribute evaluation

func NewSlice

func NewSlice(value interface{}) Slice

NewSlice creates a Slice instance with the object value

func (Slice) Contains

func (s Slice) Contains(values []interface{}) bool

Contains always return false

func (Slice) EndsWith

func (s Slice) EndsWith(value []interface{}) bool

EndsWith always return false

func (Slice) Equal

func (s Slice) Equal(value []interface{}) bool

Equal always return false

func (Slice) EqualSensitive

func (s Slice) EqualSensitive(value []interface{}) bool

EqualSensitive always return false

func (Slice) GreaterThan

func (s Slice) GreaterThan(value []interface{}) bool

GreaterThan always return false

func (Slice) GreaterThanEqual

func (s Slice) GreaterThanEqual(value []interface{}) bool

GreaterThanEqual always return false

func (Slice) In

func (s Slice) In(values []interface{}) bool

In compares the attributes held by the slice with the input values. it will first determine what type of slice this is, before casting values to the appropriate type.

func (Slice) LessThan

func (s Slice) LessThan(value []interface{}) bool

LessThan always return false

func (Slice) LessThanEqual

func (s Slice) LessThanEqual(value []interface{}) bool

LessThanEqual always return false

func (Slice) Match

func (s Slice) Match(value []interface{}) bool

Match always return false

func (Slice) StartsWith

func (s Slice) StartsWith(value []interface{}) bool

StartsWith always return false

type String

type String string

String type for clause attribute evaluation

func NewString

func NewString(value interface{}) (String, error)

NewString creates a string with the object value

func (String) Contains

func (s String) Contains(values []interface{}) bool

Contains check if the string contains the value

func (String) EndsWith

func (s String) EndsWith(values []interface{}) bool

EndsWith check if the string ends with the value

func (String) Equal

func (s String) Equal(values []interface{}) bool

Equal check if the string and value are equal

func (String) EqualSensitive

func (s String) EqualSensitive(values []interface{}) bool

EqualSensitive check if the string and value are equal (case sensitive)

func (String) GreaterThan

func (s String) GreaterThan(values []interface{}) bool

GreaterThan checks if the string is greater than the value

func (String) GreaterThanEqual

func (s String) GreaterThanEqual(values []interface{}) bool

GreaterThanEqual checks if the string is greater or equal than the value

func (String) In

func (s String) In(values []interface{}) bool

In checks if the string exist in slice of strings (value)

func (String) LessThan

func (s String) LessThan(values []interface{}) bool

LessThan checks if the string is less than the value

func (String) LessThanEqual

func (s String) LessThanEqual(values []interface{}) bool

LessThanEqual checks if the string is less or equal than the value

func (String) Match

func (s String) Match(values []interface{}) bool

Match check if the string match the regex value

func (String) StartsWith

func (s String) StartsWith(values []interface{}) bool

StartsWith check if the string starts with the value

func (String) String

func (s String) String() string

String implement Stringer interface

type Target

type Target struct {
	Identifier string                 `json:"identifier" validate:"required"`
	Name       string                 `json:"name" validate:"required"`
	Attributes map[string]interface{} `json:"attributes"`

} // @name Target

func (*Target) GetAttrType

func (t *Target) GetAttrType(attr string) (ValueType, error)

GetAttrType returns interface based on attribute value

func (*Target) GetAttrValue

func (t *Target) GetAttrValue(attr string) reflect.Value

GetAttrValue returns value from target with specified attribute

type TargetGroup

type TargetGroup struct {
	Identifier string   `json:"identifier" validate:"required"`
	Name       string   `json:"name,omitempty"`
	Included   []string `json:"included,omitempty"`
	Excluded   []string `json:"excluded,omitempty"`
	Rules      []Clause `json:"rules,omitempty"`
	Version    uint     `json:"version"`

} // @name TargetGroup

type TargetGroups

type TargetGroups []TargetGroup // @name TargetGroups

type TargetRule

type TargetRule struct {
	Targets []string `json:"targets"`
	Groups  []string `json:"groups"`
	Serve   Serve    `json:"variation"`

} // @name TargetRule

type Value

type Value interface{}

type ValueType

type ValueType interface {
	StartsWith(values []interface{}) bool
	EndsWith(values []interface{}) bool
	Match(values []interface{}) bool
	Contains(values []interface{}) bool
	EqualSensitive(values []interface{}) bool
	Equal(values []interface{}) bool
	GreaterThan(values []interface{}) bool
	GreaterThanEqual(values []interface{}) bool
	LessThan(values []interface{}) bool
	LessThanEqual(values []interface{}) bool
	In(values []interface{}) bool
}

ValueType interface used for different clause types

type Variation

type Variation struct {
	Identifier  string      `json:"identifier"`
	Name        string      `json:"name"`
	Description *string     `json:"description,omitempty"`
	Value       interface{} `json:"value"`
	// contains filtered or unexported fields

} // @name Variation

func (Variation) Bool

func (v Variation) Bool(defaultValue bool) bool

func (Variation) Int

func (v Variation) Int(defaultValue int) int

func (Variation) IsNone

func (v Variation) IsNone() bool

func (Variation) Map

func (v Variation) Map(defaultValue map[string]interface{}) map[string]interface{}

func (Variation) Number

func (v Variation) Number(defaultValue float64) float64

func (Variation) String

func (v Variation) String(defaultValue string) string

type WeightedVariation

type WeightedVariation struct {
	Variation string `json:"variation" validate:"required"`
	Weight    int    `json:"weight" validate:"required"`

} // @name WeightedVariation

Jump to

Keyboard shortcuts

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