flags

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package flags provides a runtime feature flag system for Drover. Supports gradual rollouts, kill switches, and per-project overrides.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ConfigPath string
	Watch      bool // Enable file watching for hot reload
}

Config holds manager configuration

type Flag

type Flag struct {
	ID          string       `json:"id"`
	Name        string       `json:"name"`
	Description string       `json:"description"`
	Type        FlagType     `json:"type"`
	Default     interface{}  `json:"default"`
	Value       interface{}  `json:"value"`
	Rollout     *FlagRollout `json:"rollout,omitempty"`
	CreatedAt   int64        `json:"created_at"`
	UpdatedAt   int64        `json:"updated_at"`
}

Flag represents a single feature flag

type FlagRollout

type FlagRollout struct {
	Enabled    bool     `json:"enabled"`
	Percentage int      `json:"percentage"` // 0-100
	Whitelist  []string `json:"whitelist"`  // Project IDs that always get the feature
	Blacklist  []string `json:"blacklist"`  // Project IDs that never get the feature
}

FlagRollout defines percent-based rollout configuration

type FlagType

type FlagType string

FlagType represents the type of a flag value

const (
	TypeBool   FlagType = "bool"
	TypeInt    FlagType = "int"
	TypeFloat  FlagType = "float"
	TypeString FlagType = "string"
)

type FlagUpdate

type FlagUpdate struct {
	FlagID    string
	OldValue  interface{}
	NewValue  interface{}
	Timestamp int64
}

FlagUpdate represents a flag change notification

type Manager

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

Manager manages feature flags with runtime configuration

func NewManager

func NewManager(cfg Config) (*Manager, error)

NewManager creates a new feature flag manager

func (*Manager) AddBlacklist

func (m *Manager) AddBlacklist(flagID, projectID string) error

AddBlacklist adds a project ID to a flag's blacklist

func (*Manager) AddWhitelist

func (m *Manager) AddWhitelist(flagID, projectID string) error

AddWhitelist adds a project ID to a flag's whitelist

func (*Manager) Get

func (m *Manager) Get(id string) *Flag

Get returns a flag by ID (public accessor)

func (*Manager) GetBool

func (m *Manager) GetBool(id string) bool

GetBool returns a boolean flag value

func (*Manager) GetBoolForProject

func (m *Manager) GetBoolForProject(id, projectID string) bool

GetBoolForProject returns a boolean flag value for a specific project Takes rollout configuration into account

func (*Manager) GetFloat

func (m *Manager) GetFloat(id string) float64

GetFloat returns a float flag value

func (*Manager) GetInt

func (m *Manager) GetInt(id string) int

GetInt returns an integer flag value

func (*Manager) GetRolloutConfig

func (m *Manager) GetRolloutConfig(id string) (*FlagRollout, error)

GetRolloutConfig returns the rollout configuration for a flag

func (*Manager) GetString

func (m *Manager) GetString(id string) string

GetString returns a string flag value

func (*Manager) List

func (m *Manager) List() []*Flag

List returns all flags

func (*Manager) LoadFromFile

func (m *Manager) LoadFromFile(path string) error

LoadFromFile loads flags from a JSON file

func (*Manager) SaveToFile

func (m *Manager) SaveToFile(path string) error

SaveToFile saves flags to a JSON file

func (*Manager) Set

func (m *Manager) Set(id string, value interface{}) error

Set sets a flag value

func (*Manager) SetLogger

func (m *Manager) SetLogger(logger *log.Logger)

SetLogger sets the logger for the flag manager

func (*Manager) SetPercentage

func (m *Manager) SetPercentage(flagID string, percentage int) error

SetPercentage sets the rollout percentage for a flag

func (*Manager) SetRolloutConfig

func (m *Manager) SetRolloutConfig(id string, rollout *FlagRollout) error

SetRolloutConfig sets the rollout configuration for a flag

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the flag manager

func (*Manager) Watch

func (m *Manager) Watch(ctx context.Context) <-chan *FlagUpdate

Watch subscribes to flag changes

Jump to

Keyboard shortcuts

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