featureflags

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package featureflags provides a feature flag engine for CoreForge applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine evaluates feature flags.

func NewEngine

func NewEngine(store Store) *Engine

NewEngine creates a new feature flag engine.

func (*Engine) AddTarget

func (e *Engine) AddTarget(ctx context.Context, key, targetID string) error

AddTarget adds a target (user or org ID) to a flag.

func (*Engine) DeleteFlag

func (e *Engine) DeleteFlag(ctx context.Context, key string) error

DeleteFlag removes a flag.

func (*Engine) DisableFlag

func (e *Engine) DisableFlag(ctx context.Context, key string) error

DisableFlag disables a flag globally.

func (*Engine) EnableFlag

func (e *Engine) EnableFlag(ctx context.Context, key string) error

EnableFlag enables a flag globally.

func (*Engine) GetAllFlags

func (e *Engine) GetAllFlags(ctx context.Context) ([]*Flag, error)

GetAllFlags retrieves all flags.

func (*Engine) GetFlag

func (e *Engine) GetFlag(ctx context.Context, key string) (*Flag, error)

GetFlag retrieves a flag by key.

func (*Engine) IsEnabled

func (e *Engine) IsEnabled(ctx context.Context, key string, evalCtx *EvaluationContext) (bool, error)

IsEnabled checks if a feature flag is enabled for the given context.

func (*Engine) IsEnabledSimple

func (e *Engine) IsEnabledSimple(ctx context.Context, key string) (bool, error)

IsEnabledSimple checks if a flag is enabled without context (global check).

func (*Engine) RemoveTarget

func (e *Engine) RemoveTarget(ctx context.Context, key, targetID string) error

RemoveTarget removes a target from a flag.

func (*Engine) SetFlag

func (e *Engine) SetFlag(ctx context.Context, flag *Flag) error

SetFlag creates or updates a flag.

func (*Engine) SetPercentage

func (e *Engine) SetPercentage(ctx context.Context, key string, percentage int) error

SetPercentage sets the rollout percentage for a flag.

type EvaluationContext

type EvaluationContext struct {
	// UserID is the current user's ID.
	UserID string

	// OrganizationID is the current organization's ID.
	OrganizationID string

	// Attributes are additional attributes for targeting.
	Attributes map[string]any
}

EvaluationContext provides context for flag evaluation.

type Flag

type Flag struct {
	// Key is the unique identifier for the flag.
	Key string `json:"key"`

	// Name is a human-readable name for the flag.
	Name string `json:"name,omitempty"`

	// Description explains what the flag controls.
	Description string `json:"description,omitempty"`

	// Enabled indicates if the flag is globally enabled.
	Enabled bool `json:"enabled"`

	// Percentage is the rollout percentage (0-100) for gradual rollouts.
	// Only applies when Enabled is true.
	Percentage int `json:"percentage,omitempty"`

	// Targets are specific user or organization IDs that should have the flag enabled.
	Targets []string `json:"targets,omitempty"`

	// Metadata holds additional flag-specific data.
	Metadata map[string]any `json:"metadata,omitempty"`
}

Flag represents a feature flag configuration.

type Store

type Store interface {
	// Get retrieves a flag by key.
	Get(ctx context.Context, key string) (*Flag, error)

	// GetAll retrieves all flags.
	GetAll(ctx context.Context) ([]*Flag, error)

	// Set creates or updates a flag.
	Set(ctx context.Context, flag *Flag) error

	// Delete removes a flag.
	Delete(ctx context.Context, key string) error
}

Store defines the interface for feature flag storage.

Directories

Path Synopsis
Package stores provides feature flag storage implementations.
Package stores provides feature flag storage implementations.

Jump to

Keyboard shortcuts

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