Documentation
¶
Index ¶
- type FlagConfig
- type FlagsmithConfig
- type FlagsmithProvider
- func (p *FlagsmithProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (interface{}, error)
- func (p *FlagsmithProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
- func (p *FlagsmithProvider) GetTrait(ctx context.Context, userID string, traitKey string) (interface{}, error)
- func (p *FlagsmithProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, ...) interface{}
- func (p *FlagsmithProvider) Health(ctx context.Context) error
- func (p *FlagsmithProvider) IsEnabled(ctx context.Context, key string, userCtx *UserContext) bool
- func (p *FlagsmithProvider) Name() string
- func (p *FlagsmithProvider) Refresh(ctx context.Context) error
- func (p *FlagsmithProvider) SetTrait(ctx context.Context, userID string, traitKey string, traitValue interface{}) error
- func (p *FlagsmithProvider) Start(ctx context.Context) error
- func (p *FlagsmithProvider) Stop(ctx context.Context) error
- type LaunchDarklyConfig
- type LaunchDarklyProvider
- func (p *LaunchDarklyProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (interface{}, error)
- func (p *LaunchDarklyProvider) Flush(ctx context.Context) error
- func (p *LaunchDarklyProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
- func (p *LaunchDarklyProvider) GetBoolVariation(ctx context.Context, key string, userCtx *UserContext, defaultValue bool) (bool, error)
- func (p *LaunchDarklyProvider) GetFloatVariation(ctx context.Context, key string, userCtx *UserContext, defaultValue float64) (float64, error)
- func (p *LaunchDarklyProvider) GetIntVariation(ctx context.Context, key string, userCtx *UserContext, defaultValue int) (int, error)
- func (p *LaunchDarklyProvider) GetStringVariation(ctx context.Context, key string, userCtx *UserContext, defaultValue string) (string, error)
- func (p *LaunchDarklyProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, ...) interface{}
- func (p *LaunchDarklyProvider) Health(ctx context.Context) error
- func (p *LaunchDarklyProvider) Identify(ctx context.Context, userCtx *UserContext) error
- func (p *LaunchDarklyProvider) IsEnabled(ctx context.Context, key string, userCtx *UserContext) bool
- func (p *LaunchDarklyProvider) Name() string
- func (p *LaunchDarklyProvider) Refresh(ctx context.Context) error
- func (p *LaunchDarklyProvider) Start(ctx context.Context) error
- func (p *LaunchDarklyProvider) Stop(ctx context.Context) error
- func (p *LaunchDarklyProvider) Track(ctx context.Context, userID string, event string, data interface{}) error
- type LocalProvider
- func (p *LocalProvider) Close() error
- func (p *LocalProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
- func (p *LocalProvider) GetFloat(ctx context.Context, flagKey string, userCtx *UserContext, ...) (float64, error)
- func (p *LocalProvider) GetInt(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue int) (int, error)
- func (p *LocalProvider) GetJSON(ctx context.Context, flagKey string, userCtx *UserContext, ...) (interface{}, error)
- func (p *LocalProvider) GetString(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue string) (string, error)
- func (p *LocalProvider) Health(ctx context.Context) error
- func (p *LocalProvider) Initialize(ctx context.Context) error
- func (p *LocalProvider) IsEnabled(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue bool) (bool, error)
- func (p *LocalProvider) Name() string
- func (p *LocalProvider) Refresh(ctx context.Context) error
- func (p *LocalProvider) RemoveFlag(key string)
- func (p *LocalProvider) UpdateFlag(key string, flag FlagConfig)
- type LocalProviderConfig
- type PostHogConfig
- type PostHogProvider
- func (p *PostHogProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (interface{}, error)
- func (p *PostHogProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
- func (p *PostHogProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, ...) interface{}
- func (p *PostHogProvider) Health(ctx context.Context) error
- func (p *PostHogProvider) IsEnabled(ctx context.Context, key string, userCtx *UserContext) bool
- func (p *PostHogProvider) Name() string
- func (p *PostHogProvider) Refresh(ctx context.Context) error
- func (p *PostHogProvider) Start(ctx context.Context) error
- func (p *PostHogProvider) Stop(ctx context.Context) error
- func (p *PostHogProvider) Track(ctx context.Context, userID string, event string, ...) error
- type RolloutConfig
- type TargetingRule
- type UnleashConfig
- type UnleashProvider
- func (p *UnleashProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (interface{}, error)
- func (p *UnleashProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
- func (p *UnleashProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, ...) interface{}
- func (p *UnleashProvider) GetVariant(ctx context.Context, key string, userCtx *UserContext) (string, map[string]interface{}, error)
- func (p *UnleashProvider) Health(ctx context.Context) error
- func (p *UnleashProvider) IsEnabled(ctx context.Context, key string, userCtx *UserContext) bool
- func (p *UnleashProvider) ListFeatures() []string
- func (p *UnleashProvider) Name() string
- func (p *UnleashProvider) Refresh(ctx context.Context) error
- func (p *UnleashProvider) Start(ctx context.Context) error
- func (p *UnleashProvider) Stop(ctx context.Context) error
- type UserContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 FlagsmithConfig ¶
type FlagsmithConfig struct {
// EnvironmentKey is your Flagsmith environment key
EnvironmentKey string `yaml:"environment_key" json:"environment_key"`
// APIURL is the Flagsmith API URL (default: https://edge.api.flagsmith.com/api/v1/)
APIURL string `yaml:"api_url" json:"api_url"`
// EnableLocalEvaluation enables local flag evaluation
EnableLocalEvaluation bool `yaml:"enable_local_evaluation" json:"enable_local_evaluation"`
// EnableAnalytics enables analytics tracking
EnableAnalytics bool `yaml:"enable_analytics" json:"enable_analytics"`
// CustomHeaders for additional HTTP headers
CustomHeaders map[string]string `yaml:"custom_headers" json:"custom_headers"`
// RequestTimeout in seconds
RequestTimeout int `yaml:"request_timeout" json:"request_timeout"`
// Retries for failed requests
Retries int `yaml:"retries" json:"retries"`
}
FlagsmithConfig holds configuration for Flagsmith
type FlagsmithProvider ¶
type FlagsmithProvider struct {
// contains filtered or unexported fields
}
FlagsmithProvider implements feature flags using Flagsmith
func NewFlagsmithProvider ¶
func NewFlagsmithProvider(config FlagsmithConfig, logger forge.Logger) (*FlagsmithProvider, error)
NewFlagsmithProvider creates a new Flagsmith provider
func (*FlagsmithProvider) Evaluate ¶
func (p *FlagsmithProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (interface{}, error)
Evaluate evaluates a feature flag
func (*FlagsmithProvider) GetAllFlags ¶
func (p *FlagsmithProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
GetAllFlags returns all feature flags
func (*FlagsmithProvider) GetTrait ¶
func (p *FlagsmithProvider) GetTrait(ctx context.Context, userID string, traitKey string) (interface{}, error)
GetTrait gets a user trait
func (*FlagsmithProvider) GetValue ¶
func (p *FlagsmithProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue interface{}) interface{}
GetValue returns the value of a feature flag
func (*FlagsmithProvider) Health ¶
func (p *FlagsmithProvider) Health(ctx context.Context) error
Health checks the provider health
func (*FlagsmithProvider) IsEnabled ¶
func (p *FlagsmithProvider) IsEnabled(ctx context.Context, key string, userCtx *UserContext) bool
IsEnabled checks if a feature flag is enabled
func (*FlagsmithProvider) Name ¶
func (p *FlagsmithProvider) Name() string
Name returns the provider name
func (*FlagsmithProvider) Refresh ¶
func (p *FlagsmithProvider) Refresh(ctx context.Context) error
Refresh forces a refresh of flags (if local evaluation is enabled)
func (*FlagsmithProvider) SetTrait ¶
func (p *FlagsmithProvider) SetTrait(ctx context.Context, userID string, traitKey string, traitValue interface{}) error
SetTrait sets a user trait
type LaunchDarklyConfig ¶
type LaunchDarklyConfig struct {
// SDKKey is your LaunchDarkly SDK key
SDKKey string `yaml:"sdk_key" json:"sdk_key"`
// BaseURI for custom endpoints (optional)
BaseURI string `yaml:"base_uri" json:"base_uri"`
// StreamURI for streaming connections (optional)
StreamURI string `yaml:"stream_uri" json:"stream_uri"`
// EventsURI for analytics events (optional)
EventsURI string `yaml:"events_uri" json:"events_uri"`
// StartWaitTime is the maximum time to wait for initialization
StartWaitTime time.Duration `yaml:"start_wait_time" json:"start_wait_time"`
// Offline mode for testing
Offline bool `yaml:"offline" json:"offline"`
// EnableEvents controls whether to send analytics events
EnableEvents bool `yaml:"enable_events" json:"enable_events"`
}
LaunchDarklyConfig holds configuration for LaunchDarkly
type LaunchDarklyProvider ¶
type LaunchDarklyProvider struct {
// contains filtered or unexported fields
}
LaunchDarklyProvider implements feature flags using LaunchDarkly
func NewLaunchDarklyProvider ¶
func NewLaunchDarklyProvider(config LaunchDarklyConfig, logger forge.Logger) (*LaunchDarklyProvider, error)
NewLaunchDarklyProvider creates a new LaunchDarkly provider
func (*LaunchDarklyProvider) Evaluate ¶
func (p *LaunchDarklyProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (interface{}, error)
Evaluate evaluates a feature flag
func (*LaunchDarklyProvider) Flush ¶
func (p *LaunchDarklyProvider) Flush(ctx context.Context) error
Flush flushes pending analytics events
func (*LaunchDarklyProvider) GetAllFlags ¶
func (p *LaunchDarklyProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
GetAllFlags returns all feature flags
func (*LaunchDarklyProvider) GetBoolVariation ¶
func (p *LaunchDarklyProvider) GetBoolVariation(ctx context.Context, key string, userCtx *UserContext, defaultValue bool) (bool, error)
GetBoolVariation gets a boolean flag with variation details
func (*LaunchDarklyProvider) GetFloatVariation ¶
func (p *LaunchDarklyProvider) GetFloatVariation(ctx context.Context, key string, userCtx *UserContext, defaultValue float64) (float64, error)
GetFloatVariation gets a float flag
func (*LaunchDarklyProvider) GetIntVariation ¶
func (p *LaunchDarklyProvider) GetIntVariation(ctx context.Context, key string, userCtx *UserContext, defaultValue int) (int, error)
GetIntVariation gets an integer flag
func (*LaunchDarklyProvider) GetStringVariation ¶
func (p *LaunchDarklyProvider) GetStringVariation(ctx context.Context, key string, userCtx *UserContext, defaultValue string) (string, error)
GetStringVariation gets a string flag
func (*LaunchDarklyProvider) GetValue ¶
func (p *LaunchDarklyProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue interface{}) interface{}
GetValue returns the value of a feature flag
func (*LaunchDarklyProvider) Health ¶
func (p *LaunchDarklyProvider) Health(ctx context.Context) error
Health checks the provider health
func (*LaunchDarklyProvider) Identify ¶
func (p *LaunchDarklyProvider) Identify(ctx context.Context, userCtx *UserContext) error
Identify updates user attributes in LaunchDarkly
func (*LaunchDarklyProvider) IsEnabled ¶
func (p *LaunchDarklyProvider) IsEnabled(ctx context.Context, key string, userCtx *UserContext) bool
IsEnabled checks if a feature flag is enabled
func (*LaunchDarklyProvider) Name ¶
func (p *LaunchDarklyProvider) Name() string
Name returns the provider name
func (*LaunchDarklyProvider) Refresh ¶
func (p *LaunchDarklyProvider) Refresh(ctx context.Context) error
Refresh forces a refresh of flags (LaunchDarkly handles this automatically)
func (*LaunchDarklyProvider) Start ¶
func (p *LaunchDarklyProvider) Start(ctx context.Context) error
Start starts the provider (LaunchDarkly client already initialized)
type LocalProvider ¶
type LocalProvider struct {
// contains filtered or unexported fields
}
LocalProvider is an in-memory feature flags provider
func NewLocalProvider ¶
func NewLocalProvider(config LocalProviderConfig, defaults map[string]interface{}) *LocalProvider
NewLocalProvider creates a new local provider
func (*LocalProvider) GetAllFlags ¶
func (p *LocalProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
GetAllFlags gets all flags for a user/context
func (*LocalProvider) GetFloat ¶
func (p *LocalProvider) GetFloat(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue float64) (float64, error)
GetFloat gets a float flag value
func (*LocalProvider) GetInt ¶
func (p *LocalProvider) GetInt(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue int) (int, error)
GetInt gets an integer flag value
func (*LocalProvider) GetJSON ¶
func (p *LocalProvider) GetJSON(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue interface{}) (interface{}, error)
GetJSON gets a JSON flag value
func (*LocalProvider) GetString ¶
func (p *LocalProvider) GetString(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue string) (string, error)
GetString gets a string flag value
func (*LocalProvider) Health ¶
func (p *LocalProvider) Health(ctx context.Context) error
Health checks provider health
func (*LocalProvider) Initialize ¶
func (p *LocalProvider) Initialize(ctx context.Context) error
Initialize initializes the provider
func (*LocalProvider) IsEnabled ¶
func (p *LocalProvider) IsEnabled(ctx context.Context, flagKey string, userCtx *UserContext, defaultValue bool) (bool, error)
IsEnabled checks if a boolean flag is enabled
func (*LocalProvider) Refresh ¶
func (p *LocalProvider) Refresh(ctx context.Context) error
Refresh refreshes flags (no-op for local provider)
func (*LocalProvider) RemoveFlag ¶
func (p *LocalProvider) RemoveFlag(key string)
RemoveFlag removes a flag
func (*LocalProvider) UpdateFlag ¶
func (p *LocalProvider) UpdateFlag(key string, flag FlagConfig)
UpdateFlag updates a flag configuration (for dynamic updates)
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 your 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"`
// PollingInterval for flag refresh (default: 30s)
PollingInterval time.Duration `yaml:"polling_interval" json:"polling_interval"`
// HTTPClient allows custom HTTP client
HTTPClient *http.Client `yaml:"-" json:"-"`
// EnableLocalEvaluation enables local flag evaluation (faster)
EnableLocalEvaluation bool `yaml:"enable_local_evaluation" json:"enable_local_evaluation"`
}
PostHogConfig holds configuration for PostHog feature flags
type PostHogProvider ¶
type PostHogProvider struct {
// contains filtered or unexported fields
}
PostHogProvider implements feature flags using PostHog
func NewPostHogProvider ¶
func NewPostHogProvider(config PostHogConfig, logger forge.Logger) (*PostHogProvider, error)
NewPostHogProvider creates a new PostHog provider
func (*PostHogProvider) Evaluate ¶
func (p *PostHogProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (interface{}, error)
Evaluate evaluates a feature flag using PostHog's API
func (*PostHogProvider) GetAllFlags ¶
func (p *PostHogProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
GetAllFlags returns all feature flags
func (*PostHogProvider) GetValue ¶
func (p *PostHogProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue interface{}) interface{}
GetValue returns the value of a feature flag
func (*PostHogProvider) Health ¶
func (p *PostHogProvider) Health(ctx context.Context) error
Health checks the provider health
func (*PostHogProvider) IsEnabled ¶
func (p *PostHogProvider) IsEnabled(ctx context.Context, key string, userCtx *UserContext) bool
IsEnabled checks if a feature flag is enabled
func (*PostHogProvider) Name ¶
func (p *PostHogProvider) Name() string
Name returns the provider name
func (*PostHogProvider) Refresh ¶
func (p *PostHogProvider) Refresh(ctx context.Context) error
Refresh manually refreshes flags from PostHog
func (*PostHogProvider) Start ¶
func (p *PostHogProvider) Start(ctx context.Context) error
Start starts the polling loop
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 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 for authentication
APIToken string `yaml:"api_token" json:"api_token"`
// AppName identifies your application
AppName string `yaml:"app_name" json:"app_name"`
// InstanceID uniquely identifies this instance (optional)
InstanceID string `yaml:"instance_id" json:"instance_id"`
// Environment name (optional)
Environment string `yaml:"environment" json:"environment"`
// ProjectName for multi-project setups (optional)
ProjectName string `yaml:"project_name" json:"project_name"`
// CustomHeaders for additional HTTP headers (optional)
CustomHeaders map[string]string `yaml:"custom_headers" json:"custom_headers"`
// DisableMetrics disables metrics reporting
DisableMetrics bool `yaml:"disable_metrics" json:"disable_metrics"`
}
UnleashConfig holds configuration for Unleash
type UnleashProvider ¶
type UnleashProvider struct {
// contains filtered or unexported fields
}
UnleashProvider implements feature flags using Unleash
func NewUnleashProvider ¶
func NewUnleashProvider(config UnleashConfig, logger forge.Logger) (*UnleashProvider, error)
NewUnleashProvider creates a new Unleash provider
func (*UnleashProvider) Evaluate ¶
func (p *UnleashProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (interface{}, error)
Evaluate evaluates a feature flag
func (*UnleashProvider) GetAllFlags ¶
func (p *UnleashProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]interface{}, error)
GetAllFlags returns all feature flags
func (*UnleashProvider) GetValue ¶
func (p *UnleashProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue interface{}) interface{}
GetValue returns the value of a feature flag
func (*UnleashProvider) GetVariant ¶
func (p *UnleashProvider) GetVariant(ctx context.Context, key string, userCtx *UserContext) (string, map[string]interface{}, error)
GetVariant gets a feature variant
func (*UnleashProvider) Health ¶
func (p *UnleashProvider) Health(ctx context.Context) error
Health checks the provider health
func (*UnleashProvider) IsEnabled ¶
func (p *UnleashProvider) IsEnabled(ctx context.Context, key string, userCtx *UserContext) bool
IsEnabled checks if a feature flag is enabled
func (*UnleashProvider) ListFeatures ¶
func (p *UnleashProvider) ListFeatures() []string
ListFeatures lists all available features
func (*UnleashProvider) Name ¶
func (p *UnleashProvider) Name() string
Name returns the provider name
func (*UnleashProvider) Refresh ¶
func (p *UnleashProvider) Refresh(ctx context.Context) error
Refresh forces a refresh of flags
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