cond

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const CohortKeyName = "cohort"

Variables

This section is empty.

Functions

func ToFloat64

func ToFloat64(value interface{}) (float64, error)

ToFloat64 attempts to convert the given value to a float64

Types

type BoolTyper

type BoolTyper struct {
}

func (BoolTyper) AdaptValue

func (b BoolTyper) AdaptValue(condValue, attrValue interface{}) (boolCond interface{}, boolAttr interface{}, err error)

func (BoolTyper) EvaluateKind

func (b BoolTyper) EvaluateKind(v reflect.Value) bool

type Condition

type Condition struct {
	Key           string              `json:"key"`
	Op            ConditionOpType     `json:"op"`
	LogicOperator LogicOperatorType   `json:"logic_operator"`
	Value         interface{}         `json:"value"`
	Type          ConditionValueType  `json:"type"`
	Method        StringCompareMethod `json:"method"`
	PropertyType  string              `json:"property_type"`
}

func (*Condition) Evaluate

func (c *Condition) Evaluate(attributes map[string]interface{}) bool

func (*Condition) JudgeCohort added in v1.0.5

func (c *Condition) JudgeCohort(attributes map[string]interface{}) bool

func (*Condition) JudgeExperimentCohort

func (c *Condition) JudgeExperimentCohort(attributes map[string]interface{}) bool

type ConditionOpType

type ConditionOpType string
const (
	GreaterThan        ConditionOpType = ">"
	GreaterThanOrEqual ConditionOpType = ">="
	LessThan           ConditionOpType = "<"
	LessThanOrEqual    ConditionOpType = "<="
	IN                 ConditionOpType = "in"
	NotIn              ConditionOpType = "ni"
	IsNull             ConditionOpType = "is_null"
	IsNotNull          ConditionOpType = "is_not_null"
)

type ConditionValueType

type ConditionValueType string
const (
	INT    ConditionValueType = "int"
	FLOAT  ConditionValueType = "float"
	NUMBER ConditionValueType = "number"
	STRING ConditionValueType = "string"
	BOOL   ConditionValueType = "boolean"
)

type ConditionValueTyper

type ConditionValueTyper interface {
	EvaluateKind(v reflect.Value) bool
	AdaptValue(condValue, attrValue interface{}) (adaptedCond interface{}, adaptedAttr interface{}, err error)
}

type LogicFn

type LogicFn func(x, y bool) bool

func LogicFunc

func LogicFunc(logic LogicOperatorType) LogicFn

type LogicOperatorType

type LogicOperatorType = string
const (
	AND LogicOperatorType = "&&"
	OR  LogicOperatorType = "||"
)

type MatcherFn

type MatcherFn func(attrValue interface{}, condValue interface{}, method StringCompareMethod) bool

func MathFunc

func MathFunc(op ConditionOpType) MatcherFn

type NumberTyper

type NumberTyper struct {
}

func (NumberTyper) AdaptValue

func (n NumberTyper) AdaptValue(condValue, attrValue interface{}) (float64Cond, float64Attr interface{}, err error)

func (NumberTyper) EvaluateKind

func (n NumberTyper) EvaluateKind(v reflect.Value) bool

type StringCompareMethod

type StringCompareMethod = string
const (
	DictCompare   StringCompareMethod = "dict"
	SemverCompare StringCompareMethod = "version"
)

type StringTyper

type StringTyper struct {
}

func (StringTyper) AdaptValue

func (s StringTyper) AdaptValue(condValue, attrValue interface{}) (stringCond interface{}, stringAttr interface{}, err error)

func (StringTyper) EvaluateKind

func (s StringTyper) EvaluateKind(v reflect.Value) bool

Jump to

Keyboard shortcuts

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