engine_eval

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsContextInSegment

func IsContextInSegment(ec *EngineEvaluationContext, segmentContext *SegmentContext) bool

IsContextInSegment determines if the given evaluation context matches the segment rules.

func MapEvaluationResultSegmentsToSegmentModels

func MapEvaluationResultSegmentsToSegmentModels(
	result *EvaluationResult,
) []*segments.SegmentModel

MapEvaluationResultSegmentsToSegmentModels converts evaluation result segments to segments.SegmentModel with only ID and Name populated. Only segments with API source are included (identity overrides are filtered out).

func ToString

func ToString(contextValue ContextValue) string

Types

type Comparable

type Comparable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64 |
		~string | ~bool
}

Comparable defines types that can be compared using standard operators. This includes all numeric types, strings, and booleans.

type Condition

type Condition struct {
	// The operator to use for evaluating the condition.
	Operator Operator `json:"operator"`
	// A reference to the identity trait or value in the evaluation context.
	Property string `json:"property"`
	// The value to compare against the trait or context value.
	// Can be a string or []string.
	Value any `json:"value"`
}

Represents a condition within a segment rule for feature flag evaluation.

Represents an IN condition within a segment rule for feature flag evaluation.

type ContextValue

type ContextValue interface{}

ContextValue represents allowed types: nil, int, float64, bool, string.

type EngineEvaluationContext

type EngineEvaluationContext struct {
	// Environment context required for evaluation.
	Environment EnvironmentContext `json:"environment"`
	// Features to be evaluated in the context.
	Features map[string]FeatureContext `json:"features,omitempty"`
	// Identity context used for identity-based evaluation.
	Identity *IdentityContext `json:"identity,omitempty"`
	// Segments applicable to the evaluation context.
	Segments map[string]SegmentContext `json:"segments,omitempty"`
}

A context object containing the necessary information to evaluate Flagsmith feature flags.

func MapContextAndIdentityDataToContext

func MapContextAndIdentityDataToContext(
	context EngineEvaluationContext,
	identifier string,
	traits []*trait.Trait,
) EngineEvaluationContext

MapContextAndIdentityDataToContext maps context and identity data to create an evaluation context with identity information. This function takes an existing context and enriches it with identity data including identifier and traits.

func MapEnvironmentDocumentToEvaluationContext

func MapEnvironmentDocumentToEvaluationContext(env *environments.EnvironmentModel) EngineEvaluationContext

MapEnvironmentDocumentToEvaluationContext maps an environment document model to the higher-level EngineEvaluationContext representation used for evaluation.

type EnvironmentContext

type EnvironmentContext struct {
	// Unique environment key. May be used for selecting a value for a multivariate feature, or for % split segmentation
	Key string `json:"key"`
	// An environment's human-readable name.
	Name string `json:"name"`
}

Environment context required for evaluation.

Represents an environment context for feature flag evaluation.

type EvaluationResult

type EvaluationResult struct {
	// Feature flags evaluated for the context, mapped by feature names.
	Flags map[string]*FlagResult `json:"flags"`
	// List of segments which the provided context belongs to.
	Segments []SegmentResult `json:"segments"`
}

Evaluation result object containing flag evaluation results, and segments used in the evaluation.

type FeatureContext

type FeatureContext struct {
	// Indicates whether the feature is enabled in the environment.
	Enabled bool `json:"enabled"`
	// Key used when selecting a value for a multivariate feature. Set to an internal identifier
	// or a UUID, depending on Flagsmith implementation.
	Key string `json:"key"`
	// Feature name.
	Name string `json:"name"`
	// Priority of the feature context. Lower values indicate a higher priority when multiple
	// contexts apply to the same feature.
	Priority *float64 `json:"priority,omitempty"`
	// A default environment value for the feature. If the feature is multivariate, this will be
	// the control value.
	Value any `json:"value"`
	// An array of environment default values associated with the feature. Contains a single
	// value for standard features, or multiple values for multivariate features.
	Variants []FeatureValue `json:"variants,omitempty"`
	// Metadata about the feature.
	Metadata FeatureMetadata `json:"metadata,omitempty"`
}

Represents a feature context for feature flag evaluation.

type FeatureMetadata

type FeatureMetadata struct {
	FeatureID int `json:"feature_id,omitempty"`
}

FeatureMetadata contains metadata information about a feature.

type FeatureValue

type FeatureValue struct {
	// The value of the feature.
	Value any `json:"value"`
	// The weight of the feature value variant, as a percentage number (i.e. 100.0).
	Weight float64 `json:"weight"`
	// Priority of the feature flag variant. Lower values indicate a higher priority when multiple variants apply to the same context key.
	Priority big.Int `json:"priority,omitempty"`
}

Represents a multivariate value for a feature flag.

type FlagResult

type FlagResult struct {
	// Indicates if the feature flag is enabled.
	Enabled bool `json:"enabled"`
	// Feature name.
	Name string `json:"name"`
	// Reason for the feature flag evaluation.
	Reason string `json:"reason,omitempty"`
	// Feature flag value.
	Value any `json:"value,omitempty"`
	// Metadata about the feature.
	Metadata FeatureMetadata `json:"metadata,omitempty"`
}

type FlexibleString

type FlexibleString string

FlexibleString is a type that can unmarshal from either string or number JSON values.

func (*FlexibleString) UnmarshalJSON

func (f *FlexibleString) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for FlexibleString.

type IdentityContext

type IdentityContext struct {
	// A unique identifier for an identity, used for segment and multivariate feature flag
	// targeting, and displayed in the Flagsmith UI.
	Identifier string `json:"identifier"`
	// Key used when selecting a value for a multivariate feature, or for % split segmentation.
	// Set to an internal identifier or a composite value based on the environment key and
	// identifier, depending on Flagsmith implementation.
	Key string `json:"key"`
	// A map of traits associated with the identity, where the key is the trait name and the
	// value is the trait value.
	Traits map[string]any `json:"traits,omitempty"`
}

func (*IdentityContext) UnmarshalJSON

func (ic *IdentityContext) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for IdentityContext.

type Operator

type Operator string

The operator to use for evaluating the condition.

const (
	Contains             Operator = "CONTAINS"
	Equal                Operator = "EQUAL"
	GreaterThan          Operator = "GREATER_THAN"
	GreaterThanInclusive Operator = "GREATER_THAN_INCLUSIVE"
	In                   Operator = "IN"
	IsNotSet             Operator = "IS_NOT_SET"
	IsSet                Operator = "IS_SET"
	LessThan             Operator = "LESS_THAN"
	LessThanInclusive    Operator = "LESS_THAN_INCLUSIVE"
	Modulo               Operator = "MODULO"
	NotContains          Operator = "NOT_CONTAINS"
	NotEqual             Operator = "NOT_EQUAL"
	PercentageSplit      Operator = "PERCENTAGE_SPLIT"
	Regex                Operator = "REGEX"
)

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64 |
		~string
}

Ordered defines types that support ordering operations (>, <, >=, <=). Note that bool is excluded as it doesn't support ordering.

type SegmentContext

type SegmentContext struct {
	// Key used for % split segmentation.
	Key string `json:"key"`
	// The name of the segment.
	Name string `json:"name"`
	// Metadata about the segment.
	Metadata SegmentMetadata `json:"metadata,omitempty"`
	// Feature overrides for the segment.
	Overrides []FeatureContext `json:"overrides,omitempty"`
	// Rules that define the segment.
	Rules []SegmentRule `json:"rules"`
}

Represents a segment context for feature flag evaluation.

type SegmentMetadata

type SegmentMetadata struct {
	SegmentID int `json:"segment_id,omitempty"`
	// Source of the segment.
	Source SegmentSource `json:"source,omitempty"`
}

SegmentMetadata contains metadata information about a segment.

type SegmentResult

type SegmentResult struct {
	// Segment name.
	Name string `json:"name"`
	// Metadata about the segment.
	Metadata SegmentMetadata `json:"metadata,omitempty"`
}

type SegmentRule

type SegmentRule struct {
	// Conditions that must be met for the rule to apply.
	Conditions []Condition `json:"conditions,omitempty"`
	// Sub-rules nested within the segment rule.
	Rules []SegmentRule `json:"rules,omitempty"`
	// Segment rule type. Represents a logical quantifier for the conditions and sub-rules.
	Type Type `json:"type"`
}

Represents a rule within a segment for feature flag evaluation.

type SegmentSource

type SegmentSource string

SegmentSource represents the source/origin of a segment.

const (
	// SegmentSourceAPI indicates the segment came from the Flagsmith API.
	SegmentSourceAPI SegmentSource = "api"
	// SegmentSourceIdentityOverride indicates the segment was created from identity overrides.
	SegmentSourceIdentityOverride SegmentSource = "identity_override"
)

type Trait

type Trait = trait.Trait

type Type

type Type string

Segment rule type. Represents a logical quantifier for the conditions and sub-rules.

const (
	All  Type = "ALL"
	Any  Type = "ANY"
	None Type = "NONE"
)

Jump to

Keyboard shortcuts

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