Documentation
¶
Overview ¶
Package featureflags provides feature flag evaluation with targeting rules and gradual rollout. Flags can target specific tenants, a percentage of traffic, or specific user attributes. Workflows can evaluate flags via host functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
DefaultRollout int `json:"default_rollout"` // default rollout percentage (0-100)
}
Config controls feature flag plugin behavior.
type EvaluationContext ¶
type EvaluationContext struct {
UserID string `json:"user_id"`
Attributes map[string]any `json:"attributes,omitempty"`
}
EvaluationContext holds the context for evaluating a feature flag, including the user ID and arbitrary attributes.
type EvaluationDetail ¶
type EvaluationDetail struct {
MatchedRule *MatchedRule `json:"matched_rule,omitempty"`
RolloutHit bool `json:"rollout_hit"`
}
EvaluationDetail provides details about the evaluation, including which rule matched and whether the rollout was hit.
type EvaluationResult ¶
type EvaluationResult struct {
Enabled bool `json:"enabled"`
Key string `json:"key"`
Evaluation *EvaluationDetail `json:"evaluation,omitempty"`
}
EvaluationResult is the result of evaluating a feature flag.
func EvaluateFlag ¶
func EvaluateFlag(flag *Flag, ctx EvaluationContext) EvaluationResult
EvaluateFlag evaluates a feature flag given its configuration, context, and identifiers for tenant and flag key. It follows the evaluation logic:
- If flag is not enabled, return {enabled: false}.
- Evaluate rules against context attributes (all rules must match = AND).
- If rules match (or no rules defined), check rollout percentage.
- Return result with evaluation details.
type Flag ¶
type Flag struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
Key string `json:"key"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
Rules json.RawMessage `json:"rules,omitempty"`
RolloutPercentage int `json:"rollout_percentage"`
}
Flag represents a single feature flag with its targeting rules and rollout configuration.
type MatchedRule ¶
type MatchedRule struct {
Attribute string `json:"attribute"`
Operator string `json:"operator"`
Value any `json:"value"`
}
MatchedRule describes which rule matched during evaluation.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements feature flag evaluation with targeting rules and gradual rollout for the cleat durable execution engine.
func (*Plugin) Info ¶
func (p *Plugin) Info() plugin.PluginInfo
Info returns plugin metadata for discovery and documentation.
func (*Plugin) Init ¶
Init initializes the plugin with the given environment. It parses optional configuration and sets safe defaults.
func (*Plugin) Migrations ¶
Migrations returns the database schema for feature flags. Tables are idempotent (IF NOT EXISTS) and safe to run multiple times.
func (*Plugin) RegisterHostFunctions ¶
func (p *Plugin) RegisterHostFunctions(scope plugin.FuncRegistry) error
RegisterHostFunctions registers workflow-callable functions on the scoped function registry. The plugin name is implicit -- each plugin gets its own scope, so function names need not be globally unique.