Documentation
¶
Overview ¶
Package featureflags provides a feature flag engine for CoreForge applications.
Index ¶
- type Engine
- func (e *Engine) AddTarget(ctx context.Context, key, targetID string) error
- func (e *Engine) DeleteFlag(ctx context.Context, key string) error
- func (e *Engine) DisableFlag(ctx context.Context, key string) error
- func (e *Engine) EnableFlag(ctx context.Context, key string) error
- func (e *Engine) GetAllFlags(ctx context.Context) ([]*Flag, error)
- func (e *Engine) GetFlag(ctx context.Context, key string) (*Flag, error)
- func (e *Engine) IsEnabled(ctx context.Context, key string, evalCtx *EvaluationContext) (bool, error)
- func (e *Engine) IsEnabledSimple(ctx context.Context, key string) (bool, error)
- func (e *Engine) RemoveTarget(ctx context.Context, key, targetID string) error
- func (e *Engine) SetFlag(ctx context.Context, flag *Flag) error
- func (e *Engine) SetPercentage(ctx context.Context, key string, percentage int) error
- type EvaluationContext
- type Flag
- type Store
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 (*Engine) DeleteFlag ¶
DeleteFlag removes a flag.
func (*Engine) DisableFlag ¶
DisableFlag disables a flag globally.
func (*Engine) EnableFlag ¶
EnableFlag enables a flag globally.
func (*Engine) GetAllFlags ¶
GetAllFlags retrieves all flags.
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 ¶
IsEnabledSimple checks if a flag is enabled without context (global check).
func (*Engine) RemoveTarget ¶
RemoveTarget removes a target from 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.
Click to show internal directories.
Click to hide internal directories.