eval

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BooleanFlag

type BooleanFlag struct {
	State          string          `json:"state"`
	Variants       map[string]bool `json:"variants"`
	DefaultVariant string          `json:"defaultVariant"`
	Rules          []interface{}   `json:"rules"`
}

type Flags

type Flags struct {
	BooleanFlags map[string]BooleanFlag `json:"booleanFlags"`
	StringFlags  map[string]StringFlag  `json:"stringFlags"`
	NumericFlags map[string]NumberFlag  `json:"numericFlags"`
	ObjectFlags  map[string]ObjectFlag  `json:"objectFlags"`
}

TODO: use some composition/interfaces here to reduce duplication, but we'll have to customize the marshalling

type IEvaluator

type IEvaluator interface {
	// TODO: add context param when rule evaluator is implemented
	GetState() (string, error)
	SetState(state string) error
	ResolveBooleanValue(flagKey string, defaultValue bool) (bool, error)
	ResolveStringValue(flagKey string, defaultValue string) (string, error)
	ResolveNumberValue(flagKey string, defaultValue float32) (float32, error)
	ResolveObjectValue(flagKey string, defaultValue map[string]interface{}) (map[string]interface{}, error)
}

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 {
	// contains filtered or unexported fields
}

func (*JsonEvaluator) GetState

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

func (*JsonEvaluator) ResolveBooleanValue

func (je *JsonEvaluator) ResolveBooleanValue(flagKey string, defaultValue bool) (bool, error)

func (*JsonEvaluator) ResolveNumberValue

func (je *JsonEvaluator) ResolveNumberValue(flagKey string, defaultValue float32) (float32, error)

func (*JsonEvaluator) ResolveObjectValue

func (je *JsonEvaluator) ResolveObjectValue(flagKey string, defaultValue map[string]interface{}) (map[string]interface{}, error)

func (*JsonEvaluator) ResolveStringValue

func (je *JsonEvaluator) ResolveStringValue(flagKey string, defaultValue string) (string, error)

func (*JsonEvaluator) SetState

func (je *JsonEvaluator) SetState(state string) error

type NumberFlag

type NumberFlag struct {
	State          string             `json:"state"`
	Variants       map[string]float32 `json:"variants"`
	DefaultVariant string             `json:"defaultVariant"`
	Rules          []interface{}      `json:"rules"`
}

type ObjectFlag

type ObjectFlag struct {
	State          string                            `json:"state"`
	Variants       map[string]map[string]interface{} `json:"variants"`
	DefaultVariant string                            `json:"defaultVariant"`
	Rules          []interface{}                     `json:"rules"`
}

type StringFlag

type StringFlag struct {
	State          string            `json:"state"`
	Variants       map[string]string `json:"variants"`
	DefaultVariant string            `json:"defaultVariant"`
	Rules          []interface{}     `json:"rules"`
}

Jump to

Keyboard shortcuts

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