featureflags

package
v0.2.0 Latest Latest
Warning

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

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

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

func New

func New() plugin.Plugin

New creates a new Plugin instance.

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:

  1. If flag is not enabled, return {enabled: false}.
  2. Evaluate rules against context attributes (all rules must match = AND).
  3. If rules match (or no rules defined), check rollout percentage.
  4. 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

func (p *Plugin) Init(ctx context.Context, env *plugin.Environment) error

Init initializes the plugin with the given environment. It parses optional configuration and sets safe defaults.

func (*Plugin) Migrations

func (p *Plugin) Migrations() []plugin.Migration

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.

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(mux *http.ServeMux) error

type Rule

type Rule struct {
	Attribute string `json:"attribute"`
	Operator  string `json:"operator"`
	Value     any    `json:"value"`
}

Rule is a single targeting rule with attribute, operator, and value.

Jump to

Keyboard shortcuts

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