eval

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

In package eval — what evaluation operates on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bucket

func Bucket(flagKey string, user DataContext, rollout Rollout) bool

func NewCELEnv

func NewCELEnv() (*cel.Env, error)

func NewCELEnvForContext

func NewCELEnvForContext(schema *ContextSchema) (*cel.Env, error)

Types

type BucketTrace

type BucketTrace struct {
	BucketBy     string
	BucketValue  string
	BucketNumber *int
	Percentage   int
	InRollout    bool
	Missing      bool
}

type CompiledRule

type CompiledRule struct {
	ID      string      // persisted rule id, used for diagnostics
	Source  string      //  for diagnostics/logging
	Program cel.Program // exported — accessed by Engine.Evaluate
	Rollout Rollout
	Value   any
}

type ContextField

type ContextField struct {
	Path string      `json:"path"`
	Type ContextType `json:"type"`
}

type ContextSchema

type ContextSchema struct {
	ID          string         `json:"id"`
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Fields      []ContextField `json:"fields"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	CreatedBy   *string        `json:"created_by,omitempty"`
	DeletedBy   *string        `json:"deleted_by,omitempty"`
}

type ContextType

type ContextType string
const (
	ContextTypeString    ContextType = "string"
	ContextTypeInt       ContextType = "int"
	ContextTypeDouble    ContextType = "double"
	ContextTypeBool      ContextType = "bool"
	ContextTypeTimestamp ContextType = "timestamp"
	ContextTypeList      ContextType = "list"
	ContextTypeMap       ContextType = "map"
)

func (ContextType) Valid

func (t ContextType) Valid() bool

type DataContext

type DataContext map[string]any

type Engine

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

func NewEngine

func NewEngine(celEnv *cel.Env) *Engine

func (*Engine) CompileFlag

func (e *Engine) CompileFlag(key string, config FlagConfig) (*Flag, error)

func (*Engine) CompileFlagForContext

func (e *Engine) CompileFlagForContext(key string, config FlagConfig, schema *ContextSchema) (*Flag, error)

func (*Engine) Evaluate

func (e *Engine) Evaluate(flag *Flag, data DataContext) FlagValue

Evaluate each rule in flag and return the matched rule value, or the flag default value.

func (*Engine) EvaluateConfig

func (e *Engine) EvaluateConfig(config FlagConfig, data DataContext) EvaluationTrace

func (*Engine) EvaluateConfigForContext

func (e *Engine) EvaluateConfigForContext(config FlagConfig, schema *ContextSchema, data DataContext) EvaluationTrace

func (*Engine) EvaluateResult

func (e *Engine) EvaluateResult(flag *Flag, data DataContext) EvaluationResult

func (*Engine) EvaluateTrace

func (e *Engine) EvaluateTrace(flag *Flag, data DataContext) EvaluationTrace

type EvalContext

type EvalContext struct {
	User    map[string]any `json:"user"`
	Request map[string]any `json:"request"`
	Time    *time.Time     `json:"time"`
}

type EvaluationResult

type EvaluationResult struct {
	Key       string    `json:"key,omitempty"`
	Value     any       `json:"value"`
	ValueType ValueType `json:"value_type"`
	Reason    string    `json:"reason"`
	Variant   string    `json:"variant,omitempty"`
	Error     string    `json:"error,omitempty"`
}

type EvaluationTrace

type EvaluationTrace struct {
	Key          string
	Type         ValueType
	Enabled      bool
	DefaultValue any
	Value        any
	Reason       string
	Error        string
	MatchedRule  *MatchedRuleTrace
	Bucket       *BucketTrace
	RuleResults  []RuleEvaluationTrace
}

func (EvaluationTrace) Result

func (t EvaluationTrace) Result() EvaluationResult

type Flag

type Flag struct {
	Key          string
	Type         ValueType
	Enabled      bool
	Rules        []CompiledRule // pre-compiled, ready to evaluate
	DefaultValue any
}

In memory highly accessed types

type FlagConfig

type FlagConfig struct {
	Key          string    `json:"key"`
	Description  string    `json:"description,omitempty"`
	Type         ValueType `json:"type"`
	Enabled      bool      `json:"enabled"`
	Rules        []Rule    `json:"rules"`
	DefaultValue any       `json:"default_value"`
	ContextID    *string   `json:"context_id,omitempty"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	CreatedBy    *string   `json:"created_by,omitempty"`
	UpdatedBy    *string   `json:"updated_by,omitempty"`
	DeletedBy    *string   `json:"deleted_by,omitempty"`
}

type FlagValue

type FlagValue struct {
	Type  ValueType `json:"value_type"`
	Value any       `json:"value"`
}

type MatchedRuleTrace

type MatchedRuleTrace struct {
	ID         string
	Index      int
	Expression string
	Value      any
}

type Rollout

type Rollout struct {
	Percentage int    `json:"percentage"`
	BucketBy   string `json:"bucket_by,omitempty"`
}

type Rule

type Rule struct {
	ID          string    `json:"id"`
	Description string    `json:"description,omitempty"`
	Expression  string    `json:"expression"`
	Rollout     Rollout   `json:"rollout"`
	Value       any       `json:"value"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	CreatedBy   *string   `json:"created_by,omitempty"`
	UpdatedBy   *string   `json:"updated_by,omitempty"`
	DeletedBy   *string   `json:"deleted_by,omitempty"`
}

type RuleEvaluationTrace

type RuleEvaluationTrace struct {
	ID         string
	Index      int
	Expression string
	Value      any
	Matched    bool
	Error      string
}

type ValueType

type ValueType string
const (
	ValueTypeBoolean ValueType = "boolean"
	ValueTypeString  ValueType = "string"
	ValueTypeNumber  ValueType = "number"
	ValueTypeJSON    ValueType = "json"
)

Jump to

Keyboard shortcuts

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