flaggio

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func EvalCacheKey

func EvalCacheKey(parts ...string) string

func FlagCacheKey

func FlagCacheKey(parts ...string) string

func SegmentCacheKey

func SegmentCacheKey(parts ...string) string

Types

type Constraint

type Constraint struct {
	ID        string
	Property  string
	Operation Operation
	Values    []interface{}
}

Constraint holds all the information needed for an operation to be executed.

func (*Constraint) Populate

func (c *Constraint) Populate(identifiers []Identifier)

Populate will try to populate all references on this constraint depending on the operation type. For OperationIsInSegment and OperationIsntInSegment, the flag will have a reference to a segment.

func (Constraint) Validate

func (c Constraint) Validate(usrContext map[string]interface{}) (bool, error)

Validate will check if a property in the user context passes some operation based on some configured valid values. Some operations don't need the property to be defined, while some others don't required any valid values.

type ConstraintList

type ConstraintList []*Constraint

ConstraintList is a slice of *Constraint.

func (ConstraintList) Populate

func (l ConstraintList) Populate(identifiers []Identifier)

Populate will try to populate all references on this constraint list.

func (ConstraintList) Validate

func (l ConstraintList) Validate(usrContext map[string]interface{}) (bool, error)

Validate will check if all the constraints on this list passes their validation. If any of the constraints don't validate to true, the result is false.

type Distribution

type Distribution struct {
	ID         string
	Variant    *Variant
	Percentage int
}

Distribution represents a percentage chance for a variant to be selected as the result value for the flag evaluation.

type DistributionList

type DistributionList []*Distribution

DistributionList is a slice of *Distribution.

func (DistributionList) Distribute

func (dl DistributionList) Distribute() *Variant

Distribute selects a distribution randomly, respecting the configured probability.

func (DistributionList) Evaluate

func (dl DistributionList) Evaluate(usrContext map[string]interface{}) (EvalResult, error)

Evaluate will select one of the distributions based on their percentage chance and return it's value as answer.

type EvalResult

type EvalResult struct {
	Answer interface{}
	Next   []Evaluator
	// contains filtered or unexported fields
}

EvalResult is the result generated by an Evaluator. It possibly contains an answer and/or a list of the next Evaluators that should be called.

func Evaluate

func Evaluate(usrContext map[string]interface{}, root Evaluator) (EvalResult, error)

Evaluate is the starting point for a chain of evaluations.

func (EvalResult) Stack

func (r EvalResult) Stack() (stack []*StackTrace)

Stack will generate a stack trace of the evaluation process.

type Evaluation

type Evaluation struct {
	ID          string        `json:"-"`
	FlagID      string        `json:"-"`
	FlagVersion int           `json:"-"`
	RequestHash string        `json:"-"`
	CreatedAt   time.Time     `json:"-"`
	FlagKey     string        `json:"flagKey"`
	Value       interface{}   `json:"value,omitempty"`
	Error       string        `json:"error,omitempty"`
	StackTrace  []*StackTrace `json:"stackTrace,omitempty"`
}

Evaluation is the final result of a flag evaluation. It holds the returned value associated with the key for the given user. If an error occurred, value will be nil and the error property will contain the error message. Optionally, a stack trace of the evaluation process can be attached to the object.

type EvaluationList

type EvaluationList []*Evaluation

EvaluationList is a slice of *Evaluation.

func (EvaluationList) Render

Render can enrich the EvaluationList before being returned to the user. Currently it does nothing, but is needed to satisfy the chi.Renderer interface.

type EvaluationResults

type EvaluationResults struct {
	Evaluations []*Evaluation `json:"evaluations"`
	Total       int           `json:"total"`
}

type Evaluator

type Evaluator interface {
	Evaluate(usrContext map[string]interface{}) (EvalResult, error)
}

Evaluator represents an object that can evaluate a given user context and return an answer and/or point to other evaluators that can possibly return an answer.

type Flag

type Flag struct {
	ID                    string
	Key                   string
	Name                  string
	Description           *string
	Enabled               bool
	Version               int
	Variants              []*Variant
	Rules                 []*FlagRule
	DefaultVariantWhenOn  *Variant
	DefaultVariantWhenOff *Variant
	CreatedAt             time.Time
	UpdatedAt             *time.Time
}

Flag holds all the information needed to evaluate a key to a value.

func (*Flag) Evaluate

func (f *Flag) Evaluate(usrContext map[string]interface{}) (EvalResult, error)

Evaluate will return the default variant as answer based on the flag status (on or off). If the flag is on, it will also return the list of rules to be evaluated. If there is no default variant configured for the given flag enabled state, an error is returned.

func (*Flag) GetID

func (f *Flag) GetID() string

GetID returns the flag ID.

func (*Flag) Populate

func (f *Flag) Populate(identifiers []Identifier)

Populate will try to populate all references in the list of rules.

type FlagResults

type FlagResults struct {
	Flags []*Flag `json:"flags"`
	Total int     `json:"total"`
}

type FlagRule

type FlagRule struct {
	Rule
	Distributions []*Distribution
}

FlagRule is a rule that also holds a list of distributions.

func (FlagRule) Evaluate

func (r FlagRule) Evaluate(usrContext map[string]interface{}) (EvalResult, error)

Evaluate will check that all constraints in this rule validates to true. If that is the case, it returns the list of distributions as next to be evaluated. If any of the constraints fail to pass, the rule returns an empty list of next evaluators. In any case, no answer is returned from the evaluation.

type Identifier

type Identifier interface {
	GetID() string
}

Identifier represents an object that can return an ID.

type NewConstraint

type NewConstraint struct {
	Property  string        `json:"property"`
	Operation Operation     `json:"operation"`
	Values    []interface{} `json:"values"`
}

type NewDistribution

type NewDistribution struct {
	VariantID  string `json:"variantId"`
	Percentage int    `json:"percentage"`
}

type NewFlag

type NewFlag struct {
	Key         string  `json:"key"`
	Name        string  `json:"name"`
	Description *string `json:"description"`
}

type NewFlagRule

type NewFlagRule struct {
	Constraints   []*NewConstraint   `json:"constraints"`
	Distributions []*NewDistribution `json:"distributions"`
}

type NewSegment

type NewSegment struct {
	Name        string  `json:"name"`
	Description *string `json:"description"`
}

type NewSegmentRule

type NewSegmentRule struct {
	Constraints []*NewConstraint `json:"constraints"`
}

type NewVariant

type NewVariant struct {
	Description *string     `json:"description"`
	Value       interface{} `json:"value"`
}

type Operation

type Operation string
const (
	OperationOneOf            Operation = "ONE_OF"
	OperationNotOneOf         Operation = "NOT_ONE_OF"
	OperationGreater          Operation = "GREATER"
	OperationGreaterOrEqual   Operation = "GREATER_OR_EQUAL"
	OperationLower            Operation = "LOWER"
	OperationLowerOrEqual     Operation = "LOWER_OR_EQUAL"
	OperationExists           Operation = "EXISTS"
	OperationDoesntExist      Operation = "DOESNT_EXIST"
	OperationContains         Operation = "CONTAINS"
	OperationDoesntContain    Operation = "DOESNT_CONTAIN"
	OperationStartsWith       Operation = "STARTS_WITH"
	OperationDoesntStartWith  Operation = "DOESNT_START_WITH"
	OperationEndsWith         Operation = "ENDS_WITH"
	OperationDoesntEndWith    Operation = "DOESNT_END_WITH"
	OperationMatchesRegex     Operation = "MATCHES_REGEX"
	OperationDoesntMatchRegex Operation = "DOESNT_MATCH_REGEX"
	OperationIsInSegment      Operation = "IS_IN_SEGMENT"
	OperationIsntInSegment    Operation = "ISNT_IN_SEGMENT"
	OperationIsInNetwork      Operation = "IS_IN_NETWORK"
)

func (Operation) IsValid

func (e Operation) IsValid() bool

func (Operation) MarshalGQL

func (e Operation) MarshalGQL(w io.Writer)

func (Operation) String

func (e Operation) String() string

func (*Operation) UnmarshalGQL

func (e *Operation) UnmarshalGQL(v interface{}) error

type Operator

type Operator func(usrValue interface{}, validValues []interface{}) (bool, error)

Operator runs some logic using the value from the user context and the value from the flag configuration to determine if the operation is satisfied or not.

type Rule

type Rule struct {
	ID          string
	Constraints []*Constraint
}

Rule has a list of constraints that all need to be satisfied so that it can pass.

func (Rule) GetID

func (r Rule) GetID() string

GetID returns the rule ID.

func (Rule) IsRuler

func (r Rule) IsRuler()

IsRuler is defined so that Rule can implement the Ruler interface.

func (*Rule) Populate

func (r *Rule) Populate(identifiers []Identifier)

Populate will try to populate all references in the list of constraints.

type Ruler

type Ruler interface {
	IsRuler()
}

type Segment

type Segment struct {
	ID          string
	Name        string
	Description *string
	Rules       []*SegmentRule
	CreatedAt   time.Time
	UpdatedAt   *time.Time
}

Segment represents a category of users that can be grouped based on a set of rules.

func (*Segment) GetID

func (s *Segment) GetID() string

GetID returns the segment ID.

func (*Segment) Validate

func (s *Segment) Validate(usrContext map[string]interface{}) (bool, error)

Validate will check if any of the segment rules passes validation. If so, the validation is successful, otherwise it returns false.

type SegmentRule

type SegmentRule struct {
	Rule
}

SegmentRule is a rule to be used by segments.

type StackTrace

type StackTrace struct {
	Type   string      `json:"type"`
	ID     *string     `json:"id"`
	Answer interface{} `json:"answer"`
}

StackTrace contains detailed information about the evaluation process. Type is the type of the model object that evaluated the user context ID holds the ID of the same object, if any. Answer is the evaluation answer, if any.

type UpdateFlag

type UpdateFlag struct {
	Key                   *string `json:"key"`
	Name                  *string `json:"name"`
	Description           *string `json:"description"`
	Enabled               *bool   `json:"enabled"`
	DefaultVariantWhenOn  *string `json:"defaultVariantWhenOn"`
	DefaultVariantWhenOff *string `json:"defaultVariantWhenOff"`
}

type UpdateFlagRule

type UpdateFlagRule struct {
	Constraints   []*NewConstraint   `json:"constraints"`
	Distributions []*NewDistribution `json:"distributions"`
}

type UpdateSegment

type UpdateSegment struct {
	Name        *string `json:"name"`
	Description *string `json:"description"`
}

type UpdateSegmentRule

type UpdateSegmentRule struct {
	Constraints []*NewConstraint `json:"constraints"`
}

type UpdateVariant

type UpdateVariant struct {
	Description *string     `json:"description"`
	Value       interface{} `json:"value"`
}

type User

type User struct {
	ID          string                 `json:"id"`
	Context     map[string]interface{} `json:"context"`
	UpdatedAt   time.Time              `json:"updatedAt"`
	Evaluations *EvaluationResults     `json:"evaluations"`
}

type UserContext

type UserContext map[string]interface{}

UserContext is a map of strings and one of: int64, float64, bool, string

func (UserContext) UnmarshalJSON

func (a UserContext) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the bytes into UserContext

type UserResults

type UserResults struct {
	Users []*User `json:"users"`
	Total int     `json:"total"`
}

type Variant

type Variant struct {
	ID          string
	Description *string
	Value       interface{}
}

Variant represents a value that can be returned by the evaluation process of a Flag.

Directories

Path Synopsis
Package flaggio_mock is a generated GoMock package.
Package flaggio_mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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