Documentation
¶
Index ¶
- type FlagConfig
- type FlagsmithConfig
- type FlagsmithProvider
- func (p *FlagsmithProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (any, error)
- func (p *FlagsmithProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, error)
- func (p *FlagsmithProvider) GetTrait(ctx context.Context, userID string, traitKey string) (any, error)
- func (p *FlagsmithProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue any) any
- 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 any) 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) (any, error)
- func (p *LaunchDarklyProvider) Flush(ctx context.Context) error
- func (p *LaunchDarklyProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, 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, defaultValue any) any
- 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 any) error
- type LocalProvider
- func (p *LocalProvider) Close() error
- func (p *LocalProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, 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, defaultValue any) (any, 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) (any, error)
- func (p *PostHogProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, error)
- func (p *PostHogProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue any) any
- 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, properties map[string]any) error
- type RolloutConfig
- type TargetingRule
- type UnleashConfig
- type UnleashProvider
- func (p *UnleashProvider) Evaluate(ctx context.Context, key string, userCtx *UserContext) (any, error)
- func (p *UnleashProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, error)
- func (p *UnleashProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue any) any
- func (p *UnleashProvider) GetVariant(ctx context.Context, key string, userCtx *UserContext) (string, map[string]any, 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 `json:"key" yaml:"key"`
// Name is the human-readable name
Name string `json:"name" yaml:"name"`
// Description describes what this flag controls
Description string `json:"description" yaml:"description"`
// Type is the flag value type: "boolean", "string", "number", "json"
Type string `json:"type" yaml:"type"`
// Enabled is the default enabled state for boolean flags
Enabled bool `json:"enabled" yaml:"enabled"`
// Value is the default value for non-boolean flags
Value any `json:"value" yaml:"value"`
// Targeting defines user/group targeting rules
Targeting []TargetingRule `json:"targeting" yaml:"targeting"`
// Rollout defines percentage-based rollout
Rollout *RolloutConfig `json:"rollout" yaml:"rollout"`
}
FlagConfig defines a single feature flag.
type FlagsmithConfig ¶
type FlagsmithConfig struct {
// EnvironmentKey is your Flagsmith environment key
EnvironmentKey string `json:"environment_key" yaml:"environment_key"`
// APIURL is the Flagsmith API URL (default: https://edge.api.flagsmith.com/api/v1/)
APIURL string `json:"api_url" yaml:"api_url"`
// EnableLocalEvaluation enables local flag evaluation
EnableLocalEvaluation bool `json:"enable_local_evaluation" yaml:"enable_local_evaluation"`
// EnableAnalytics enables analytics tracking
EnableAnalytics bool `json:"enable_analytics" yaml:"enable_analytics"`
// CustomHeaders for additional HTTP headers
CustomHeaders map[string]string `json:"custom_headers" yaml:"custom_headers"`
// RequestTimeout in seconds
RequestTimeout int `json:"request_timeout" yaml:"request_timeout"`
// Retries for failed requests
Retries int `json:"retries" yaml:"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) (any, error)
Evaluate evaluates a feature flag.
func (*FlagsmithProvider) GetAllFlags ¶
func (p *FlagsmithProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, error)
GetAllFlags returns all feature flags.
func (*FlagsmithProvider) GetTrait ¶
func (p *FlagsmithProvider) GetTrait(ctx context.Context, userID string, traitKey string) (any, error)
GetTrait gets a user trait.
func (*FlagsmithProvider) GetValue ¶
func (p *FlagsmithProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue any) any
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 any) error
SetTrait sets a user trait.
type LaunchDarklyConfig ¶
type LaunchDarklyConfig struct {
// SDKKey is your LaunchDarkly SDK key
SDKKey string `json:"sdk_key" yaml:"sdk_key"`
// BaseURI for custom endpoints (optional)
BaseURI string `json:"base_uri" yaml:"base_uri"`
// StreamURI for streaming connections (optional)
StreamURI string `json:"stream_uri" yaml:"stream_uri"`
// EventsURI for analytics events (optional)
EventsURI string `json:"events_uri" yaml:"events_uri"`
// StartWaitTime is the maximum time to wait for initialization
StartWaitTime time.Duration `json:"start_wait_time" yaml:"start_wait_time"`
// Offline mode for testing
Offline bool `json:"offline" yaml:"offline"`
// EnableEvents controls whether to send analytics events
EnableEvents bool `json:"enable_events" yaml:"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) (any, 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]any, 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 any) any
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]any) *LocalProvider
NewLocalProvider creates a new local provider.
func (*LocalProvider) GetAllFlags ¶
func (p *LocalProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, 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 any) (any, 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 `json:"flags" yaml:"flags"`
}
LocalProviderConfig for local in-memory provider.
type PostHogConfig ¶
type PostHogConfig struct {
// APIKey is your PostHog project API key
APIKey string `json:"api_key" yaml:"api_key"`
// Host is the PostHog host (default: https://app.posthog.com)
Host string `json:"host" yaml:"host"`
// PersonalAPIKey for admin operations (optional)
PersonalAPIKey string `json:"personal_api_key" yaml:"personal_api_key"`
// PollingInterval for flag refresh (default: 30s)
PollingInterval time.Duration `json:"polling_interval" yaml:"polling_interval"`
// HTTPClient allows custom HTTP client
HTTPClient *http.Client `json:"-" yaml:"-"`
// EnableLocalEvaluation enables local flag evaluation (faster)
EnableLocalEvaluation bool `json:"enable_local_evaluation" yaml:"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) (any, error)
Evaluate evaluates a feature flag using PostHog's API.
func (*PostHogProvider) GetAllFlags ¶
func (p *PostHogProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, error)
GetAllFlags returns all feature flags.
func (*PostHogProvider) GetValue ¶
func (p *PostHogProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue any) any
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 `json:"percentage" yaml:"percentage"`
// Attribute to use for consistent hashing (default: "user_id")
Attribute string `json:"attribute" yaml:"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 `json:"attribute" yaml:"attribute"`
// Operator is the comparison operator: "equals", "contains", "in", "not_in"
Operator string `json:"operator" yaml:"operator"`
// Values are the values to match against
Values []string `json:"values" yaml:"values"`
// Value is the flag value for matching users
Value any `json:"value" yaml:"value"`
}
TargetingRule defines targeting rules for a flag.
type UnleashConfig ¶
type UnleashConfig struct {
// URL is the Unleash API URL
URL string `json:"url" yaml:"url"`
// APIToken for authentication
APIToken string `json:"api_token" yaml:"api_token"`
// AppName identifies your application
AppName string `json:"app_name" yaml:"app_name"`
// InstanceID uniquely identifies this instance (optional)
InstanceID string `json:"instance_id" yaml:"instance_id"`
// Environment name (optional)
Environment string `json:"environment" yaml:"environment"`
// ProjectName for multi-project setups (optional)
ProjectName string `json:"project_name" yaml:"project_name"`
// CustomHeaders for additional HTTP headers (optional)
CustomHeaders map[string]string `json:"custom_headers" yaml:"custom_headers"`
// DisableMetrics disables metrics reporting
DisableMetrics bool `json:"disable_metrics" yaml:"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) (any, error)
Evaluate evaluates a feature flag.
func (*UnleashProvider) GetAllFlags ¶
func (p *UnleashProvider) GetAllFlags(ctx context.Context, userCtx *UserContext) (map[string]any, error)
GetAllFlags returns all feature flags.
func (*UnleashProvider) GetValue ¶
func (p *UnleashProvider) GetValue(ctx context.Context, key string, userCtx *UserContext, defaultValue any) any
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]any, 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]any `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.