Documentation ¶
Index ¶
- Variables
- func EvalCacheKey(parts ...string) string
- func FlagCacheKey(parts ...string) string
- func SegmentCacheKey(parts ...string) string
- type Constraint
- type ConstraintList
- type Distribution
- type DistributionList
- type EvalResult
- type Evaluation
- type EvaluationList
- type EvaluationResults
- type Evaluator
- type Flag
- type FlagResults
- type FlagRule
- type Identifier
- type NewConstraint
- type NewDistribution
- type NewFlag
- type NewFlagRule
- type NewSegment
- type NewSegmentRule
- type NewVariant
- type Operation
- type Operator
- type Rule
- type Ruler
- type Segment
- type SegmentRule
- type StackTrace
- type UpdateFlag
- type UpdateFlagRule
- type UpdateSegment
- type UpdateSegmentRule
- type UpdateVariant
- type User
- type UserContext
- type UserResults
- type Variant
Constants ¶
This section is empty.
Variables ¶
var AllOperation = []Operation{ OperationOneOf, OperationNotOneOf, OperationGreater, OperationGreaterOrEqual, OperationLower, OperationLowerOrEqual, OperationExists, OperationDoesntExist, OperationContains, OperationDoesntContain, OperationStartsWith, OperationDoesntStartWith, OperationEndsWith, OperationDoesntEndWith, OperationMatchesRegex, OperationDoesntMatchRegex, OperationIsInSegment, OperationIsntInSegment, OperationIsInNetwork, }
Functions ¶
func EvalCacheKey ¶
func FlagCacheKey ¶
func SegmentCacheKey ¶
Types ¶
type Constraint ¶
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.
type Distribution ¶
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 ¶
func (l EvaluationList) Render(w http.ResponseWriter, r *http.Request) error
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) Populate ¶
func (f *Flag) Populate(identifiers []Identifier)
Populate will try to populate all references in the list of rules.
type FlagResults ¶
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 NewDistribution ¶
type NewFlagRule ¶
type NewFlagRule struct { Constraints []*NewConstraint `json:"constraints"` Distributions []*NewDistribution `json:"distributions"` }
type NewSegment ¶
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) MarshalGQL ¶
func (*Operation) UnmarshalGQL ¶
type Operator ¶
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) 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 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.
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 UpdateFlagRule ¶
type UpdateFlagRule struct { Constraints []*NewConstraint `json:"constraints"` Distributions []*NewDistribution `json:"distributions"` }
type UpdateSegment ¶
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