Documentation ¶
Index ¶
- Constants
- type FBClient
- func (client *FBClient) AllLatestFlagsVariations(user FBUser) (AllFlagState, error)
- func (client *FBClient) BoolVariation(featureFlagKey string, user FBUser, defaultValue bool) (bool, EvalDetail, error)
- func (client *FBClient) Close() error
- func (client *FBClient) DoubleVariation(featureFlagKey string, user FBUser, defaultValue float64) (float64, EvalDetail, error)
- func (client *FBClient) Flush() error
- func (client *FBClient) GetDataUpdateStatusProvider() DataUpdateStatusProvider
- func (client *FBClient) Identify(user FBUser) error
- func (client *FBClient) InitializeFromExternalJson(jsonStr string) (bool, error)
- func (client *FBClient) IntVariation(featureFlagKey string, user FBUser, defaultValue int) (int, EvalDetail, error)
- func (client *FBClient) IsFlagKnown(featureFlagKey string) bool
- func (client *FBClient) IsInitialized() bool
- func (client *FBClient) JsonVariation(featureFlagKey string, user FBUser, defaultValue interface{}) (interface{}, EvalDetail, error)
- func (client *FBClient) TrackNumericMetric(user FBUser, eventName string, metricValue float64) error
- func (client *FBClient) TrackNumericMetrics(user FBUser, metrics map[string]float64) error
- func (client *FBClient) TrackPercentageMetric(user FBUser, eventName string) error
- func (client *FBClient) TrackPercentageMetrics(user FBUser, eventNames ...string) error
- func (client *FBClient) Variation(featureFlagKey string, user FBUser, defaultValue string) (string, EvalDetail, error)
- type FBConfig
Constants ¶
const ( ExptKeyPrefix = "expt" ReasonFlagOff = "flag off" ReasonTargetMatch = "target match" ReasonRuleMatch = "rule match" ReasonFallthrough = "fall through all rules" ReasonClientNotReady = "client not ready" ReasonFlagNotFound = "flag not found" ReasonWrongType = "wrong type" ReasonUserNotSpecified = "user not specified" ReasonError = "error in evaluation" FlagNameUnknown = "flag Name unknown" ThanClause = "Than" GeClause = "BiggerEqualThan" GtClause = "BiggerThan" LeClause = "LessEqualThan" LtClause = "LessThan" EqClause = "Equal" NeqClause = "NotEqual" ContainsClause = "Contains" NotContainClause = "NotContain" IsOneOfClause = "IsOneOf" NotOneOfClause = "NotOneOf" StartsWithClause = "StartsWith" EndsWithClause = "EndsWith" IsTrueClause = "IsTrue" IsFalseClause = "IsFalse" MatchRegexClause = "MatchRegex" NotMatchRegexClause = "NotMatchRegex" IsInSegmentClause = "User is in segment" NotInSegmentClause = "User is not in segment" FlagJsonType = "json" FlagBoolType = "boolean" FlagNumericType = "number" FlagStringType = "string" )
const ( INFO = iota WARN ERROR TRACE = -2 DEBUG = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FBClient ¶
type FBClient struct {
// contains filtered or unexported fields
}
func MakeCustomFBClient ¶
func MakeCustomFBClient(envSecret string, streamingUrl string, eventUrl string, config FBConfig) (*FBClient, error)
MakeCustomFBClient creates a new client instance that connects to your feature flag center with the custom configuration.
The FBConfig allows customization of all SDK properties; some of these are represented directly as fields in FBConfig, while others are set by builder methods on a more specific configuration object. See FBConfig for details.
Unless it is configured to be offline with FBConfig.Offline, the client will begin attempting to connect to feature flag center as soon as you call this constructor. The constructor will return when it successfully connects, or when the timeout set by the FBConfig.StartWait parameter expires, whichever comes first.
If the timeout(15s) elapsed without a successful connection, it still returns a client instance-- in an initializing state, where feature flags will return default values-- and the error value is initializationTimeout. In this case, it will still continue trying to connect in the background.
If there was an unexpected error such that it cannot succeed by retrying-- for instance, the envSecret key is invalid or an DNS error-- it will return a client instance in an uninitialized state, and the error value is initializationFailed.
The way to monitor the client's status, use FBClient.IsInitialized or FBClient.GetDataUpdateStatusProvider.
client, _ := featbit.MakeCustomFBClient(envSecret, streamingUrl, eventUrl, config) if !client.IsInitialized() { // do whatever is appropriate if initialization has timed out }
If you set FBConfig.StartWait to zero, the function will return immediately after creating the client instance, and do any further initialization in the background.
client, _ := featbit.MakeCustomFBClient(envSecret, streamingUrl, eventUrl, config) // later... ok := client.GetDataSourceStatusProvider().WaitForOKState(10 * time.Second) if !ok { // do whatever is appropriate if initialization has timed out }
The only time it returns nil instead of a client instance is if the client cannot be created at all due to an invalid configuration. This is rare, but could happen if for example you specified a custom TLS certificate file that did not load a valid certificate, you inputted an invalid env secret key, etc...
func NewFBClient ¶
NewFBClient creates a new client instance that connects to your feature flag center with the default configuration. For advanced configuration options, use MakeCustomFBClient. Calling NewFBClient is exactly equivalent to calling MakeCustomClient with the config parameter set to a default value.
Unless it is configured to be offline with FBConfig.Offline, the client will begin attempting to connect to feature flag center as soon as you call this constructor. The constructor will return when it successfully connects, or when the timeout set by the FBConfig.StartWait parameter expires, whichever comes first.
If the timeout(15s) elapsed without a successful connection, it still returns a client instance-- in an initializing state, where feature flags will return default values-- and the error value is initializationTimeout. In this case, it will still continue trying to connect in the background.
If there was an unexpected error such that it cannot succeed by retrying-- for instance, the envSecret key is invalid or an DNS error-- it will return a client instance in an uninitialized state, and the error value is initializationFailed.
The way to monitor the client's status, use FBClient.IsInitialized or FBClient.GetDataUpdateStatusProvider.
client, _ := featbit.NewFBClient(envSecret, streamingUrl, eventUrl) if !client.IsInitialized() { // do whatever is appropriate if initialization has timed out }
If you set FBConfig.StartWait to zero, the function will return immediately after creating the client instance, and do any further initialization in the background.
client, _ := featbit.MakeCustomFBClient(envSecret, streamingUrl, eventUrl, config) // later... ok := client.GetDataSourceStatusProvider().WaitForOKState(10 * time.Second) if !ok { // do whatever is appropriate if initialization has timed out }
The only time it returns nil instead of a client instance is if the client cannot be created at all due to an invalid configuration. This is rare, but could happen if for example you specified a custom TLS certificate file that did not load a valid certificate, you inputted an invalid env secret key, etc...
func (*FBClient) AllLatestFlagsVariations ¶
AllLatestFlagsVariations returns a list of all feature flags value with details for a given user, including the reason describes the way the value was determined.
The return type AllFlagState could be used as a cache that provides the flag value to a client side sdk or a front-end app. See more details in AllFlagState.
This method does not send insight events back to feature flag center. See interfaces.AllFlagState
func (*FBClient) BoolVariation ¶
func (client *FBClient) BoolVariation(featureFlagKey string, user FBUser, defaultValue bool) (bool, EvalDetail, error)
BoolVariation calculates the value of a feature flag for a given user, return a bool variation for the given user, or defaultValue if the flag is disabled or an error occurs; the details that explains how the flag value is explained and the error if any.
The method sends insight events back to feature flag center
func (*FBClient) Close ¶
Close shuts down the FBClient. After calling this, the FBClient should no longer be used. The method will block until all pending events (if any) been sent.
func (*FBClient) DoubleVariation ¶
func (client *FBClient) DoubleVariation(featureFlagKey string, user FBUser, defaultValue float64) (float64, EvalDetail, error)
DoubleVariation calculates the value of a feature flag for a given user, return a float variation for the given user, or defaultValue if the flag is disabled or an error occurs; the details that explains how the flag value is explained and the error if any.
The method sends insight events back to feature flag center
func (*FBClient) Flush ¶
Flush tells the FBClient that all pending events (if any) should be delivered as soon as possible. Flushing is asynchronous, so this method will return before it is complete. However, if you call Close(), events are guaranteed to be sent before that method returns.
func (*FBClient) GetDataUpdateStatusProvider ¶
func (client *FBClient) GetDataUpdateStatusProvider() DataUpdateStatusProvider
GetDataUpdateStatusProvider returns an interface for tracking the status of the interfaces.DataSynchronizer.
The data synchronizer is the component that the SDK uses to get feature flags, segments such as a streaming connection. The interfaces.DataUpdateStatusProvider has methods for checking whether the interfaces.DataSynchronizer is currently operational and tracking changes in this status.
The interfaces.DataUpdateStatusProvider is recommended to use when SDK starts in asynchronous mode
func (*FBClient) InitializeFromExternalJson ¶
InitializeFromExternalJson initializes FeatBit client in the offline mode
Return false if the json can't be parsed or client is not in the offline mode
func (*FBClient) IntVariation ¶
func (client *FBClient) IntVariation(featureFlagKey string, user FBUser, defaultValue int) (int, EvalDetail, error)
IntVariation calculates the value of a feature flag for a given user, return an int variation for the given user, or defaultValue if the flag is disabled or an error occurs; the details that explains how the flag value is explained and the error if any.
The method sends insight events back to feature flag center
func (*FBClient) IsFlagKnown ¶
IsFlagKnown returns true if feature flag is registered in the feature flag center, false if any error or flag is not existed
func (*FBClient) IsInitialized ¶
func (*FBClient) JsonVariation ¶
func (client *FBClient) JsonVariation(featureFlagKey string, user FBUser, defaultValue interface{}) (interface{}, EvalDetail, error)
JsonVariation calculates the value of a feature flag for a given user, return a json object variation for the given user, or defaultValue if the flag is disabled or an error occurs; the details that explains how the flag value is explained and the error if any.
The method sends insight events back to feature flag center
func (*FBClient) TrackNumericMetric ¶
func (client *FBClient) TrackNumericMetric(user FBUser, eventName string, metricValue float64) error
TrackNumericMetric reports that a user has performed an event, and associates it with a metric value. This value is used by the experimentation feature in numeric custom metrics.
The eventName normally corresponds to the event Name of a metric that you have created through the experiment dashboard in the feature flag center
func (*FBClient) TrackNumericMetrics ¶
TrackNumericMetrics reports that a user tracks that a user performed a series of events with metric values. These values are used by the experimentation feature in numeric custom metrics.
The eventName normally corresponds to the event Name of a metric that you have created through the experiment dashboard in the feature flag center
func (*FBClient) TrackPercentageMetric ¶
TrackPercentageMetric reports that a user has performed an event, and associates it with a default value. This value is used by the experimentation feature in percentage custom metrics.
The eventName normally corresponds to the event Name of a metric that you have created through the experiment dashboard in the feature flag center
func (*FBClient) TrackPercentageMetrics ¶
TrackPercentageMetrics reports that a user tracks that a user performed a series of events with default values. These values are used by the experimentation feature in percentage custom metrics.
The eventName normally corresponds to the event Name of a metric that you have created through the experiment dashboard in the feature flag center
func (*FBClient) Variation ¶
func (client *FBClient) Variation(featureFlagKey string, user FBUser, defaultValue string) (string, EvalDetail, error)
Variation calculates the value of a feature flag for a given user, return a string variation for the given user, or defaultValue if the flag is disabled or an error occurs; the details that explains how the flag value is explained and the error if any.
The method sends insight events back to feature flag center
type FBConfig ¶
type FBConfig struct { // Offline whether SDK is offline Offline bool // StartWait how long the constructor will block awaiting a successful data sync // // Setting this to a zero or negative duration will not block and cause the constructor to return immediately. StartWait time.Duration // NetworkFactory a factory object which sets the SDK networking configuration Depending on the implementation, // the factory may be a builder that allows you to set other configuration options as well. NetworkFactory NetworkFactory // DataStorageFactory a factory object which sets the implementation of interfaces.DataStorage to be used for holding feature flags and // related data received from feature flag center. Depending on the implementation, the factory may be a builder that // allows you to set other configuration options as well. DataStorageFactory DataStorageFactory // DataSynchronizerFactory a factory object which sets the implementation of the interfaces.DataSynchronizer that receives feature flag data // from feature flag center. // // Depending on the implementation, the factory may be a builder that allows you to set other configuration options as well. DataSynchronizerFactory DataSynchronizerFactory // InsightProcessorFactory a factory object which sets the implementation of interfaces.InsightProcessor to be used for processing analytics events. // // Depending on the implementation, the factory may be a builder that allows you to set other configuration options as well. InsightProcessorFactory InsightProcessorFactory // LogLevel FeaBit log level LogLevel int }
FBConfig exposes advanced configuration options for the FBClient
config = FBConfig{Offline: true}
var DefaultFBConfig *FBConfig = &FBConfig{ Offline: false, StartWait: 15 * time.Second, NetworkFactory: factories.NewNetworkBuilder(), DataStorageFactory: factories.NewInMemoryStorageBuilder(), DataSynchronizerFactory: factories.NewStreamingBuilder(), InsightProcessorFactory: factories.NewInsightProcessorBuilder(), LogLevel: INFO, }
DefaultFBConfig FeatBit default configuration