Documentation ¶
Overview ¶
Package config //
Package config //
Package config //
Package config //
Index ¶
- Constants
- Variables
- type OptimizelyAttribute
- type OptimizelyAudience
- type OptimizelyConfig
- type OptimizelyEvent
- type OptimizelyExperiment
- type OptimizelyFeature
- type OptimizelyVariable
- type OptimizelyVariation
- type OptionFunc
- func WithDatafileAccessToken(datafileAccessToken string) OptionFunc
- func WithDatafileURLTemplate(datafileTemplate string) OptionFunc
- func WithInitialDatafile(datafile []byte) OptionFunc
- func WithPollingInterval(interval time.Duration) OptionFunc
- func WithRequester(requester utils.Requester) OptionFunc
- type PollingProjectConfigManager
- func (cm *PollingProjectConfigManager) GetConfig() (ProjectConfig, error)
- func (cm *PollingProjectConfigManager) GetOptimizelyConfig() *OptimizelyConfig
- func (cm *PollingProjectConfigManager) OnProjectConfigUpdate(callback func(notification.ProjectConfigUpdateNotification)) (int, error)
- func (cm *PollingProjectConfigManager) RemoveOnProjectConfigUpdate(id int) error
- func (cm *PollingProjectConfigManager) Start(ctx context.Context)
- func (cm *PollingProjectConfigManager) SyncConfig()
- type ProjectConfig
- type ProjectConfigManager
- type StaticProjectConfigManager
- func NewStaticProjectConfigManager(config ProjectConfig, logger logging.OptimizelyLogProducer) *StaticProjectConfigManager
- func NewStaticProjectConfigManagerFromPayload(payload []byte, logger logging.OptimizelyLogProducer) (*StaticProjectConfigManager, error)
- func NewStaticProjectConfigManagerFromURL(sdkKey string) (*StaticProjectConfigManager, error)
- func NewStaticProjectConfigManagerWithOptions(sdkKey string, configMangerOptions ...OptionFunc) *StaticProjectConfigManager
- func (cm *StaticProjectConfigManager) GetConfig() (ProjectConfig, error)
- func (cm *StaticProjectConfigManager) GetOptimizelyConfig() *OptimizelyConfig
- func (cm *StaticProjectConfigManager) OnProjectConfigUpdate(callback func(notification.ProjectConfigUpdateNotification)) (int, error)
- func (cm *StaticProjectConfigManager) RemoveOnProjectConfigUpdate(id int) error
Constants ¶
const AuthDatafileURLTemplate = "https://config.optimizely.com/datafiles/auth/%s.json"
AuthDatafileURLTemplate is used to construct the endpoint for retrieving authenticated datafile from the CDN
const DatafileURLTemplate = "https://cdn.optimizely.com/datafiles/%s.json"
DatafileURLTemplate is used to construct the endpoint for retrieving regular datafile from the CDN
const DefaultPollingInterval = 5 * time.Minute // default to 5 minutes for polling
DefaultPollingInterval sets default interval for polling manager
const LastModified = "Last-Modified"
LastModified header key for response
const ModifiedSince = "If-Modified-Since"
ModifiedSince header key for request
Variables ¶
var Err403Forbidden = errors.New("unable to fetch fresh datafile (consider rechecking SDK key), status code: 403 Forbidden")
Err403Forbidden is 403Forbidden specific error
Functions ¶
This section is empty.
Types ¶
type OptimizelyAttribute ¶ added in v1.7.0
OptimizelyAttribute has attribute info
type OptimizelyAudience ¶ added in v1.7.0
type OptimizelyAudience struct { ID string `json:"id"` Name string `json:"name"` Conditions string `json:"conditions"` }
OptimizelyAudience has audience info
type OptimizelyConfig ¶
type OptimizelyConfig struct { EnvironmentKey string `json:"environmentKey"` SdkKey string `json:"sdkKey"` Revision string `json:"revision"` // This experimentsMap is for experiments of legacy projects only. // For flag projects, experiment keys are not guaranteed to be unique // across multiple flags, so this map may not include all experiments // when keys conflict. ExperimentsMap map[string]OptimizelyExperiment `json:"experimentsMap"` FeaturesMap map[string]OptimizelyFeature `json:"featuresMap"` Attributes []OptimizelyAttribute `json:"attributes"` Audiences []OptimizelyAudience `json:"audiences"` Events []OptimizelyEvent `json:"events"` // contains filtered or unexported fields }
OptimizelyConfig is a snapshot of the experiments and features in the project config
func NewOptimizelyConfig ¶
func NewOptimizelyConfig(projConfig ProjectConfig) *OptimizelyConfig
NewOptimizelyConfig constructs OptimizelyConfig object
func (OptimizelyConfig) GetDatafile ¶ added in v1.4.0
func (c OptimizelyConfig) GetDatafile() string
GetDatafile returns a string representation of the environment's datafile
type OptimizelyEvent ¶ added in v1.7.0
type OptimizelyEvent struct { ID string `json:"id"` Key string `json:"key"` ExperimentIds []string `json:"experimentIds"` }
OptimizelyEvent has event info
type OptimizelyExperiment ¶
type OptimizelyExperiment struct { ID string `json:"id"` Key string `json:"key"` Audiences string `json:"audiences"` VariationsMap map[string]OptimizelyVariation `json:"variationsMap"` }
OptimizelyExperiment has experiment info
type OptimizelyFeature ¶
type OptimizelyFeature struct { ID string `json:"id"` Key string `json:"key"` ExperimentRules []OptimizelyExperiment `json:"experimentRules"` DeliveryRules []OptimizelyExperiment `json:"deliveryRules"` VariablesMap map[string]OptimizelyVariable `json:"variablesMap"` // Deprecated: Use experimentRules and deliveryRules ExperimentsMap map[string]OptimizelyExperiment `json:"experimentsMap"` }
OptimizelyFeature has feature info
type OptimizelyVariable ¶
type OptimizelyVariable struct { ID string `json:"id"` Key string `json:"key"` Type string `json:"type"` Value string `json:"value"` }
OptimizelyVariable has variable info
type OptimizelyVariation ¶
type OptimizelyVariation struct { ID string `json:"id"` Key string `json:"key"` FeatureEnabled bool `json:"featureEnabled"` VariablesMap map[string]OptimizelyVariable `json:"variablesMap"` }
OptimizelyVariation has variation info
type OptionFunc ¶
type OptionFunc func(*PollingProjectConfigManager)
OptionFunc is used to provide custom configuration to the PollingProjectConfigManager.
func WithDatafileAccessToken ¶ added in v1.3.0
func WithDatafileAccessToken(datafileAccessToken string) OptionFunc
WithDatafileAccessToken is an optional function, sets a passed datafile access token
func WithDatafileURLTemplate ¶
func WithDatafileURLTemplate(datafileTemplate string) OptionFunc
WithDatafileURLTemplate is an optional function, sets a passed datafile URL template
func WithInitialDatafile ¶
func WithInitialDatafile(datafile []byte) OptionFunc
WithInitialDatafile is an optional function, sets a passed datafile
func WithPollingInterval ¶
func WithPollingInterval(interval time.Duration) OptionFunc
WithPollingInterval is an optional function, sets a passed polling interval
func WithRequester ¶
func WithRequester(requester utils.Requester) OptionFunc
WithRequester is an optional function, sets a passed requester
type PollingProjectConfigManager ¶
type PollingProjectConfigManager struct {
// contains filtered or unexported fields
}
PollingProjectConfigManager maintains a dynamic copy of the project config by continuously polling for the datafile from the Optimizely CDN at a given (configurable) interval.
func NewAsyncPollingProjectConfigManager ¶ added in v1.1.0
func NewAsyncPollingProjectConfigManager(sdkKey string, pollingMangerOptions ...OptionFunc) *PollingProjectConfigManager
NewAsyncPollingProjectConfigManager returns an instance of the async polling config manager with the customized configuration
func NewPollingProjectConfigManager ¶
func NewPollingProjectConfigManager(sdkKey string, pollingMangerOptions ...OptionFunc) *PollingProjectConfigManager
NewPollingProjectConfigManager returns an instance of the polling config manager with the customized configuration
func (*PollingProjectConfigManager) GetConfig ¶
func (cm *PollingProjectConfigManager) GetConfig() (ProjectConfig, error)
GetConfig returns the project config
func (*PollingProjectConfigManager) GetOptimizelyConfig ¶
func (cm *PollingProjectConfigManager) GetOptimizelyConfig() *OptimizelyConfig
GetOptimizelyConfig returns the optimizely project config
func (*PollingProjectConfigManager) OnProjectConfigUpdate ¶
func (cm *PollingProjectConfigManager) OnProjectConfigUpdate(callback func(notification.ProjectConfigUpdateNotification)) (int, error)
OnProjectConfigUpdate registers a handler for ProjectConfigUpdate notifications
func (*PollingProjectConfigManager) RemoveOnProjectConfigUpdate ¶
func (cm *PollingProjectConfigManager) RemoveOnProjectConfigUpdate(id int) error
RemoveOnProjectConfigUpdate removes handler for ProjectConfigUpdate notification with given id
func (*PollingProjectConfigManager) Start ¶
func (cm *PollingProjectConfigManager) Start(ctx context.Context)
Start starts the polling
func (*PollingProjectConfigManager) SyncConfig ¶
func (cm *PollingProjectConfigManager) SyncConfig()
SyncConfig downloads datafile and updates projectConfig
type ProjectConfig ¶
type ProjectConfig interface { GetDatafile() string GetAccountID() string GetAnonymizeIP() bool GetAttributeID(id string) string // returns "" if there is no id GetAttributeByKey(key string) (entities.Attribute, error) GetAudienceList() (audienceList []entities.Audience) GetAudienceByID(string) (entities.Audience, error) GetAudienceMap() map[string]entities.Audience GetBotFiltering() bool GetEvents() []entities.Event GetEventByKey(string) (entities.Event, error) GetExperimentByKey(string) (entities.Experiment, error) GetFeatureByKey(string) (entities.Feature, error) GetVariableByKey(featureKey string, variableKey string) (entities.Variable, error) GetExperimentList() []entities.Experiment GetRolloutList() (rolloutList []entities.Rollout) GetFeatureList() []entities.Feature GetGroupByID(string) (entities.Group, error) GetProjectID() string GetRevision() string SendFlagDecisions() bool GetSdkKey() string GetEnvironmentKey() string GetAttributes() []entities.Attribute GetFlagVariationsMap() map[string][]entities.Variation }
ProjectConfig represents the project's experiments and feature flags and contains methods for accessing the them.
type ProjectConfigManager ¶
type ProjectConfigManager interface { GetConfig() (ProjectConfig, error) GetOptimizelyConfig() *OptimizelyConfig RemoveOnProjectConfigUpdate(id int) error OnProjectConfigUpdate(callback func(notification.ProjectConfigUpdateNotification)) (int, error) }
ProjectConfigManager maintains an instance of the ProjectConfig
type StaticProjectConfigManager ¶
type StaticProjectConfigManager struct {
// contains filtered or unexported fields
}
StaticProjectConfigManager maintains a static copy of the project config
func NewStaticProjectConfigManager ¶
func NewStaticProjectConfigManager(config ProjectConfig, logger logging.OptimizelyLogProducer) *StaticProjectConfigManager
NewStaticProjectConfigManager creates a new instance of the manager with the given project config
func NewStaticProjectConfigManagerFromPayload ¶
func NewStaticProjectConfigManagerFromPayload(payload []byte, logger logging.OptimizelyLogProducer) (*StaticProjectConfigManager, error)
NewStaticProjectConfigManagerFromPayload returns new instance of StaticProjectConfigManager for payload
func NewStaticProjectConfigManagerFromURL ¶
func NewStaticProjectConfigManagerFromURL(sdkKey string) (*StaticProjectConfigManager, error)
NewStaticProjectConfigManagerFromURL returns new instance of StaticProjectConfigManager for URL
func NewStaticProjectConfigManagerWithOptions ¶ added in v1.3.0
func NewStaticProjectConfigManagerWithOptions(sdkKey string, configMangerOptions ...OptionFunc) *StaticProjectConfigManager
NewStaticProjectConfigManagerWithOptions creates a new instance of the manager with the given sdk key and some options
func (*StaticProjectConfigManager) GetConfig ¶
func (cm *StaticProjectConfigManager) GetConfig() (ProjectConfig, error)
GetConfig returns the project config
func (*StaticProjectConfigManager) GetOptimizelyConfig ¶
func (cm *StaticProjectConfigManager) GetOptimizelyConfig() *OptimizelyConfig
GetOptimizelyConfig returns the optimizely project config
func (*StaticProjectConfigManager) OnProjectConfigUpdate ¶
func (cm *StaticProjectConfigManager) OnProjectConfigUpdate(callback func(notification.ProjectConfigUpdateNotification)) (int, error)
OnProjectConfigUpdate here satisfies interface
func (*StaticProjectConfigManager) RemoveOnProjectConfigUpdate ¶
func (cm *StaticProjectConfigManager) RemoveOnProjectConfigUpdate(id int) error
RemoveOnProjectConfigUpdate here satisfies interface