Documentation
¶
Index ¶
- func NewExtension(opts ...ConfigOption) forge.Extension
- func NewExtensionWithConfig(config Config) forge.Extension
- type Config
- type ConfigOption
- func WithCache(enabled bool, ttl time.Duration) ConfigOption
- func WithConfig(config Config) ConfigOption
- func WithDefaultFlags(flags map[string]interface{}) ConfigOption
- func WithEnabled(enabled bool) ConfigOption
- func WithFlagsmith(apiURL, environmentKey string) ConfigOption
- func WithLaunchDarkly(sdkKey string) ConfigOption
- func WithLocalFlags(flags map[string]FlagConfig) ConfigOption
- func WithPostHog(apiKey, host string) ConfigOption
- func WithProvider(provider string) ConfigOption
- func WithRefreshInterval(interval time.Duration) ConfigOption
- func WithUnleash(url, apiToken, appName string) ConfigOption
- type EvaluationResult
- type Extension
- type FlagConfig
- type FlagEvaluationEvent
- type FlagValue
- type FlagsmithConfig
- type LaunchDarklyConfig
- type LocalProviderConfig
- type PostHogConfig
- type Provider
- func NewFlagsmithProvider(config FlagsmithConfig, defaults map[string]interface{}) (Provider, error)
- func NewLaunchDarklyProvider(config LaunchDarklyConfig, defaults map[string]interface{}) (Provider, error)
- func NewLocalProvider(config LocalProviderConfig, defaults map[string]interface{}) Provider
- func NewPostHogProvider(config PostHogConfig, defaults map[string]interface{}) (Provider, error)
- func NewUnleashProvider(config UnleashConfig, defaults map[string]interface{}) (Provider, error)
- type RolloutConfig
- type Service
- func (s *Service) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
- func (s *Service) GetFloat(ctx context.Context, flagKey string, userCtx *UserContext, ...) float64
- func (s *Service) GetInt(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue int) int
- func (s *Service) GetJSON(ctx context.Context, flagKey string, userCtx *UserContext, ...) interface{}
- func (s *Service) GetString(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue string) string
- func (s *Service) IsEnabled(ctx context.Context, flagKey string, userCtx *UserContext) bool
- func (s *Service) IsEnabledWithDefault(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue bool) bool
- func (s *Service) Refresh(ctx context.Context) error
- type TargetingRule
- type UnleashConfig
- type UserContext
- func (uc *UserContext) GetAttribute(key string) (interface{}, bool)
- func (uc *UserContext) GetAttributeString(key string) (string, error)
- func (uc *UserContext) HasGroup(group string) bool
- func (uc *UserContext) WithAttribute(key string, value interface{}) *UserContext
- func (uc *UserContext) WithCountry(country string) *UserContext
- func (uc *UserContext) WithEmail(email string) *UserContext
- func (uc *UserContext) WithGroups(groups []string) *UserContext
- func (uc *UserContext) WithIP(ip string) *UserContext
- func (uc *UserContext) WithName(name string) *UserContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewExtension ¶
func NewExtension(opts ...ConfigOption) forge.Extension
NewExtension creates a new feature flags extension
func NewExtensionWithConfig ¶
NewExtensionWithConfig creates a new extension with complete config
Types ¶
type Config ¶
type Config struct {
// Enabled determines if feature flags extension is enabled
Enabled bool `yaml:"enabled" json:"enabled"`
// Provider specifies the backend provider
// Options: "local", "launchdarkly", "unleash", "flagsmith", "posthog"
Provider string `yaml:"provider" json:"provider"`
// RefreshInterval is how often to refresh flags from remote provider
RefreshInterval time.Duration `yaml:"refresh_interval" json:"refresh_interval"`
// EnableCache enables local caching of flag values
EnableCache bool `yaml:"enable_cache" json:"enable_cache"`
// CacheTTL is the cache TTL for flag values
CacheTTL time.Duration `yaml:"cache_ttl" json:"cache_ttl"`
// Local provider settings
Local LocalProviderConfig `yaml:"local" json:"local"`
// LaunchDarkly provider settings
LaunchDarkly LaunchDarklyConfig `yaml:"launchdarkly" json:"launchdarkly"`
// Unleash provider settings
Unleash UnleashConfig `yaml:"unleash" json:"unleash"`
// Flagsmith provider settings
Flagsmith FlagsmithConfig `yaml:"flagsmith" json:"flagsmith"`
// PostHog provider settings
PostHog PostHogConfig `yaml:"posthog" json:"posthog"`
// DefaultFlags are default flag values (used as fallback)
DefaultFlags map[string]interface{} `yaml:"default_flags" json:"default_flags"`
}
Config holds feature flags extension configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default feature flags configuration
type ConfigOption ¶
type ConfigOption func(*Config)
ConfigOption configures the feature flags extension
func WithCache ¶
func WithCache(enabled bool, ttl time.Duration) ConfigOption
WithCache enables caching with TTL
func WithDefaultFlags ¶
func WithDefaultFlags(flags map[string]interface{}) ConfigOption
WithDefaultFlags sets default flag values
func WithEnabled ¶
func WithEnabled(enabled bool) ConfigOption
WithEnabled sets whether feature flags is enabled
func WithFlagsmith ¶
func WithFlagsmith(apiURL, environmentKey string) ConfigOption
WithFlagsmith configures Flagsmith provider
func WithLaunchDarkly ¶
func WithLaunchDarkly(sdkKey string) ConfigOption
WithLaunchDarkly configures LaunchDarkly provider
func WithLocalFlags ¶
func WithLocalFlags(flags map[string]FlagConfig) ConfigOption
WithLocalFlags sets local provider flags
func WithPostHog ¶
func WithPostHog(apiKey, host string) ConfigOption
WithPostHog configures PostHog provider
func WithProvider ¶
func WithProvider(provider string) ConfigOption
WithProvider sets the feature flags provider
func WithRefreshInterval ¶
func WithRefreshInterval(interval time.Duration) ConfigOption
WithRefreshInterval sets the refresh interval
func WithUnleash ¶
func WithUnleash(url, apiToken, appName string) ConfigOption
WithUnleash configures Unleash provider
type EvaluationResult ¶
type EvaluationResult struct {
// FlagKey is the flag key
FlagKey string `json:"flag_key"`
// Value is the evaluated value
Value interface{} `json:"value"`
// VariationIndex is the variation index (if applicable)
VariationIndex int `json:"variation_index,omitempty"`
// Reason is the evaluation reason
Reason string `json:"reason"`
// RuleID is the ID of the rule that matched (if applicable)
RuleID string `json:"rule_id,omitempty"`
}
EvaluationResult holds the result of a flag evaluation
type Extension ¶
type Extension struct {
*forge.BaseExtension
// contains filtered or unexported fields
}
Extension implements forge.Extension for feature flags
func (*Extension) Dependencies ¶
Dependencies returns extension dependencies
type FlagConfig ¶
type FlagConfig struct {
// Key is the unique flag identifier
Key string `yaml:"key" json:"key"`
// Name is the human-readable name
Name string `yaml:"name" json:"name"`
// Description describes what this flag controls
Description string `yaml:"description" json:"description"`
// Type is the flag value type: "boolean", "string", "number", "json"
Type string `yaml:"type" json:"type"`
// Enabled is the default enabled state for boolean flags
Enabled bool `yaml:"enabled" json:"enabled"`
// Value is the default value for non-boolean flags
Value interface{} `yaml:"value" json:"value"`
// Targeting defines user/group targeting rules
Targeting []TargetingRule `yaml:"targeting" json:"targeting"`
// Rollout defines percentage-based rollout
Rollout *RolloutConfig `yaml:"rollout" json:"rollout"`
}
FlagConfig defines a single feature flag
type FlagEvaluationEvent ¶
type FlagEvaluationEvent struct {
// FlagKey is the flag key
FlagKey string `json:"flag_key"`
// UserContext is the user context
UserContext *UserContext `json:"user_context"`
// Value is the evaluated value
Value interface{} `json:"value"`
// Default indicates if the default value was used
Default bool `json:"default"`
// Reason is the evaluation reason
Reason string `json:"reason"`
// Timestamp is when the evaluation occurred
Timestamp int64 `json:"timestamp"`
}
FlagEvaluationEvent represents a flag evaluation event for analytics
type FlagValue ¶
type FlagValue struct {
// Key is the flag key
Key string `json:"key"`
// Value is the flag value
Value interface{} `json:"value"`
// Enabled indicates if the flag is enabled (for boolean flags)
Enabled bool `json:"enabled"`
// Variation is the variation key/name
Variation string `json:"variation,omitempty"`
// Reason is the evaluation reason
Reason string `json:"reason,omitempty"`
}
FlagValue represents a feature flag value with metadata
type FlagsmithConfig ¶
type FlagsmithConfig struct {
// APIURL is the Flagsmith API URL
APIURL string `yaml:"api_url" json:"api_url"`
// EnvironmentKey is the Flagsmith environment key
EnvironmentKey string `yaml:"environment_key" json:"environment_key"`
}
FlagsmithConfig for Flagsmith provider
type LaunchDarklyConfig ¶
type LaunchDarklyConfig struct {
// SDKKey is the LaunchDarkly SDK key
SDKKey string `yaml:"sdk_key" json:"sdk_key"`
// Timeout for API requests
Timeout time.Duration `yaml:"timeout" json:"timeout"`
}
LaunchDarklyConfig for LaunchDarkly provider
type LocalProviderConfig ¶
type LocalProviderConfig struct {
// Flags are the static flag definitions
Flags map[string]FlagConfig `yaml:"flags" json:"flags"`
}
LocalProviderConfig for local in-memory provider
type PostHogConfig ¶
type PostHogConfig struct {
// APIKey is the PostHog project API key
APIKey string `yaml:"api_key" json:"api_key"`
// Host is the PostHog host (default: https://app.posthog.com)
Host string `yaml:"host" json:"host"`
// PersonalAPIKey for admin operations (optional)
PersonalAPIKey string `yaml:"personal_api_key" json:"personal_api_key"`
// EnableLocalEvaluation enables local flag evaluation (faster)
EnableLocalEvaluation bool `yaml:"enable_local_evaluation" json:"enable_local_evaluation"`
// PollingInterval for flag refresh (default: 30s)
PollingInterval time.Duration `yaml:"polling_interval" json:"polling_interval"`
}
PostHogConfig for PostHog provider
type Provider ¶
type Provider interface {
// Name returns the provider name
Name() string
// Initialize initializes the provider
Initialize(ctx context.Context) error
// IsEnabled checks if a boolean flag is enabled for a user/context
IsEnabled(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue bool) (bool, error)
// GetString gets a string flag value
GetString(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue string) (string, error)
// GetInt gets an integer flag value
GetInt(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue int) (int, error)
// GetFloat gets a float flag value
GetFloat(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue float64) (float64, error)
// GetJSON gets a JSON flag value
GetJSON(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue interface{}) (interface{}, error)
// GetAllFlags gets all flags for a user/context
GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
// Refresh refreshes flags from remote source
Refresh(ctx context.Context) error
// Close closes the provider
Close() error
// Health checks provider health
Health(ctx context.Context) error
}
Provider defines the interface for feature flag providers
func NewFlagsmithProvider ¶
func NewFlagsmithProvider(config FlagsmithConfig, defaults map[string]interface{}) (Provider, error)
NewFlagsmithProvider creates a new Flagsmith provider NOTE: Temporarily disabled until dependencies are resolved
func NewLaunchDarklyProvider ¶
func NewLaunchDarklyProvider(config LaunchDarklyConfig, defaults map[string]interface{}) (Provider, error)
NewLaunchDarklyProvider creates a new LaunchDarkly provider NOTE: Temporarily disabled until dependencies are resolved
func NewLocalProvider ¶
func NewLocalProvider(config LocalProviderConfig, defaults map[string]interface{}) Provider
NewLocalProvider creates a new local in-memory provider
func NewPostHogProvider ¶
func NewPostHogProvider(config PostHogConfig, defaults map[string]interface{}) (Provider, error)
NewPostHogProvider creates a new PostHog provider NOTE: Temporarily disabled until dependencies are resolved
func NewUnleashProvider ¶
func NewUnleashProvider(config UnleashConfig, defaults map[string]interface{}) (Provider, error)
NewUnleashProvider creates a new Unleash provider NOTE: Temporarily disabled until dependencies are resolved
type RolloutConfig ¶
type RolloutConfig struct {
// Percentage of users to enable (0-100)
Percentage int `yaml:"percentage" json:"percentage"`
// Attribute to use for consistent hashing (default: "user_id")
Attribute string `yaml:"attribute" json:"attribute"`
}
RolloutConfig defines percentage-based rollout
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides high-level feature flag operations
func NewService ¶
NewService creates a new feature flags service
func (*Service) GetAllFlags ¶
func (s *Service) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
GetAllFlags gets all feature flags for a user/context
func (*Service) GetFloat ¶
func (s *Service) GetFloat(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue float64) float64
GetFloat gets a float feature flag value
func (*Service) GetInt ¶
func (s *Service) GetInt(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue int) int
GetInt gets an integer feature flag value
func (*Service) GetJSON ¶
func (s *Service) GetJSON(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue interface{}) interface{}
GetJSON gets a JSON feature flag value
func (*Service) GetString ¶
func (s *Service) GetString(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue string) string
GetString gets a string feature flag value
func (*Service) IsEnabledWithDefault ¶
func (s *Service) IsEnabledWithDefault(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue bool) bool
IsEnabledWithDefault checks if a boolean feature flag is enabled with a custom default
type TargetingRule ¶
type TargetingRule struct {
// Attribute is the user attribute to match (e.g., "user_id", "email", "group")
Attribute string `yaml:"attribute" json:"attribute"`
// Operator is the comparison operator: "equals", "contains", "in", "not_in"
Operator string `yaml:"operator" json:"operator"`
// Values are the values to match against
Values []string `yaml:"values" json:"values"`
// Value is the flag value for matching users
Value interface{} `yaml:"value" json:"value"`
}
TargetingRule defines targeting rules for a flag
type UnleashConfig ¶
type UnleashConfig struct {
// URL is the Unleash API URL
URL string `yaml:"url" json:"url"`
// APIToken is the Unleash API token
APIToken string `yaml:"api_token" json:"api_token"`
// AppName is the application name
AppName string `yaml:"app_name" json:"app_name"`
// Environment is the environment name
Environment string `yaml:"environment" json:"environment"`
// InstanceID is a unique instance identifier
InstanceID string `yaml:"instance_id" json:"instance_id"`
}
UnleashConfig for Unleash provider
type UserContext ¶
type UserContext struct {
// UserID is the unique user identifier
UserID string `json:"user_id"`
// Email is the user email
Email string `json:"email,omitempty"`
// Name is the user name
Name string `json:"name,omitempty"`
// Groups are user group memberships
Groups []string `json:"groups,omitempty"`
// Attributes are custom attributes for targeting
Attributes map[string]interface{} `json:"attributes,omitempty"`
// IP is the user IP address
IP string `json:"ip,omitempty"`
// Country is the user country code
Country string `json:"country,omitempty"`
}
UserContext holds user/context information for flag evaluation
func NewUserContext ¶
func NewUserContext(userID string) *UserContext
NewUserContext creates a new user context for flag evaluation
func (*UserContext) GetAttribute ¶
func (uc *UserContext) GetAttribute(key string) (interface{}, bool)
GetAttribute gets a custom attribute
func (*UserContext) GetAttributeString ¶
func (uc *UserContext) GetAttributeString(key string) (string, error)
GetAttributeString gets a string attribute
func (*UserContext) HasGroup ¶
func (uc *UserContext) HasGroup(group string) bool
HasGroup checks if user is in a group
func (*UserContext) WithAttribute ¶
func (uc *UserContext) WithAttribute(key string, value interface{}) *UserContext
WithAttribute sets a custom attribute
func (*UserContext) WithCountry ¶
func (uc *UserContext) WithCountry(country string) *UserContext
WithCountry sets the user country
func (*UserContext) WithEmail ¶
func (uc *UserContext) WithEmail(email string) *UserContext
WithEmail sets the user email
func (*UserContext) WithGroups ¶
func (uc *UserContext) WithGroups(groups []string) *UserContext
WithGroups sets the user groups
func (*UserContext) WithIP ¶
func (uc *UserContext) WithIP(ip string) *UserContext
WithIP sets the user IP address
func (*UserContext) WithName ¶
func (uc *UserContext) WithName(name string) *UserContext
WithName sets the user name