Documentation
¶
Index ¶
- type FlagRow
- type OverrideRow
- type Provider
- func (p *Provider) AllFlags(ctx context.Context, evalCtx featureflag.EvaluationContext) ([]featureflag.FlagValue, error)
- func (p *Provider) Evaluate(ctx context.Context, key string, evalCtx featureflag.EvaluationContext) (featureflag.FlagValue, error)
- func (p *Provider) Name() string
- func (p *Provider) NotifyChange(key string, value any, flagType featureflag.FlagType)
- func (p *Provider) Subscribe(fn func(featureflag.FlagChangeEvent)) (cancel func())
- type RuleRow
- type Store
- func (s *Store) AddRule(ctx context.Context, r *RuleRow) error
- func (s *Store) Close() error
- func (s *Store) DeleteFlag(ctx context.Context, key string) error
- func (s *Store) DeleteOverride(ctx context.Context, id int64) error
- func (s *Store) DeleteRule(ctx context.Context, id int64) error
- func (s *Store) GetFlag(ctx context.Context, key string) (*FlagRow, error)
- func (s *Store) GetOverrides(ctx context.Context, flagKey string) ([]OverrideRow, error)
- func (s *Store) GetRules(ctx context.Context, flagKey string) ([]RuleRow, error)
- func (s *Store) ListFlags(ctx context.Context) ([]FlagRow, error)
- func (s *Store) UpsertFlag(ctx context.Context, f *FlagRow) error
- func (s *Store) UpsertOverride(ctx context.Context, o *OverrideRow) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FlagRow ¶
type FlagRow struct {
Key string `json:"key"`
Type string `json:"type"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
DefaultVal string `json:"default_val"`
Tags []string `json:"tags"`
Percentage float64 `json:"percentage"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
FlagRow represents a row in the feature_flags table.
type OverrideRow ¶
type OverrideRow struct {
ID int64 `json:"id"`
FlagKey string `json:"flag_key"`
Scope string `json:"scope"` // "user" or "group"
ScopeKey string `json:"scope_key"` // user ID or group name
Value string `json:"value"`
}
OverrideRow represents a flag override for a specific user or group.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is the built-in generic feature-flag provider. Flag definitions, targeting rules, and overrides are stored in a SQLite database.
Evaluation order:
- Disabled check -> return default value
- User overrides (scope="user", scope_key=UserKey)
- Group overrides (scope="group", matched via "groups" attribute)
- Targeting rules (evaluated top-to-bottom by priority)
- Percentage rollout (deterministic hash of userKey+flagKey)
- Default value
func NewProvider ¶
NewProvider creates a generic provider backed by the given store.
func (*Provider) AllFlags ¶
func (p *Provider) AllFlags(ctx context.Context, evalCtx featureflag.EvaluationContext) ([]featureflag.FlagValue, error)
AllFlags implements featureflag.Provider.
func (*Provider) Evaluate ¶
func (p *Provider) Evaluate(ctx context.Context, key string, evalCtx featureflag.EvaluationContext) (featureflag.FlagValue, error)
Evaluate implements featureflag.Provider. It resolves the flag through the six-step evaluation order documented on the Provider type.
func (*Provider) NotifyChange ¶
func (p *Provider) NotifyChange(key string, value any, flagType featureflag.FlagType)
NotifyChange should be called after mutating a flag (e.g., from the admin API) to inform subscribers of the change.
func (*Provider) Subscribe ¶
func (p *Provider) Subscribe(fn func(featureflag.FlagChangeEvent)) (cancel func())
Subscribe implements featureflag.Provider.
type RuleRow ¶
type RuleRow struct {
ID int64 `json:"id"`
FlagKey string `json:"flag_key"`
Priority int `json:"priority"`
Attribute string `json:"attribute"`
Operator string `json:"operator"`
Value string `json:"value"`
ServeValue string `json:"serve_value"`
}
RuleRow represents a targeting rule row.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists flag definitions, targeting rules, and overrides in SQLite.
func NewStore ¶
NewStore opens (or creates) a SQLite database at the given path and ensures the schema tables exist.
func NewStoreFromDB ¶
NewStoreFromDB wraps an existing *sql.DB (useful for testing).
func (*Store) DeleteFlag ¶
DeleteFlag removes a flag and its related rules and overrides (cascade).
func (*Store) DeleteOverride ¶
DeleteOverride removes an override by ID.
func (*Store) DeleteRule ¶
DeleteRule removes a targeting rule by ID.
func (*Store) GetOverrides ¶
GetOverrides returns all overrides for a flag.
func (*Store) GetRules ¶
GetRules returns all targeting rules for a flag, ordered by priority ascending.
func (*Store) UpsertFlag ¶
UpsertFlag creates or updates a flag definition.
func (*Store) UpsertOverride ¶
func (s *Store) UpsertOverride(ctx context.Context, o *OverrideRow) error
UpsertOverride creates or updates an override.