ffc

package
v0.0.0-...-dc352d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ConfigDefaultStartWaitTime  = time.Duration(time.Second)
	HttpConfigDefaultConnTime   = time.Duration(time.Second * 10)
	HttpConfigDefaultSocketTime = time.Duration(time.Second * 15)
)
View Source
const (
	FLAGS = iota
	FLUSH
	SHUTDOWN
	METRICS
)

Variables

This section is empty.

Functions

func GetCurrentUser

func GetCurrentUser() model.FFCUser

func ProcessMessage

func ProcessMessage(message string)

ProcessMessage receive message from web socket and convert to all object. @Param message the data receive from socket

func Remove

func Remove()

func SetCurrentUser

func SetCurrentUser(user model.FFCUser, inherit bool)

Types

type BasicConfig

type BasicConfig struct {
	EnvSecret string
	OffLine   bool
}

type Client

type Client struct {
	Offline   bool
	Evaluator Evaluator
	EnvSecret string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(envSecret string, config *Config) Client

NewClient create a new client instance.

func (*Client) BoolVariation

func (c *Client) BoolVariation(featureFlagKey string, user model.FFCUser, defaultValue bool) bool

BoolVariation Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) BoolVariationDetail

func (c *Client) BoolVariationDetail(featureFlagKey string, user model.FFCUser,
	defaultValue bool) model.FlagState

BoolVariationDetail Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) FloatVariation

func (c *Client) FloatVariation(featureFlagKey string, user model.FFCUser, defaultValue float64) float64

FloatVariation Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) FloatVariationDetail

func (c *Client) FloatVariationDetail(featureFlagKey string, user model.FFCUser,
	defaultValue float64) model.FlagState

FloatVariationDetail Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) Flush

func (c *Client) Flush()

Flush Flushes all pending events.

func (*Client) GetAllLatestFlagsVariations

func (c *Client) GetAllLatestFlagsVariations(user model.FFCUser) model.AllFlagState

GetAllLatestFlagsVariations Returns a list of all feature flags value with details for a given user, including the reason that describes the way the value was determined, that can be used on the client side sdk or a front end . @Param user the end user requesting the flag @Return

func (*Client) GetAllUserTags

func (c *Client) GetAllUserTags() []model.UserTag

GetAllUserTags return a list of user tags used to instantiate a {@link FFCUser} @Return a list of user tags

func (*Client) InitializeFromExternalJson

func (c *Client) InitializeFromExternalJson(jsonStr string) bool

InitializeFromExternalJson initialization in the offline mode @Param featureFlagKey the unique key for the feature flag

func (*Client) Int64Variation

func (c *Client) Int64Variation(featureFlagKey string, user model.FFCUser, defaultValue int64) int64

Int64Variation Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) Int64VariationDetail

func (c *Client) Int64VariationDetail(featureFlagKey string, user model.FFCUser,
	defaultValue int64) model.FlagState

Int64VariationDetail Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) IntVariation

func (c *Client) IntVariation(featureFlagKey string, user model.FFCUser, defaultValue int) int

IntVariation Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) IntVariationDetail

func (c *Client) IntVariationDetail(featureFlagKey string, user model.FFCUser,
	defaultValue int) model.FlagState

IntVariationDetail Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) IsEnable

func (c *Client) IsEnable(featureFlagKey string, user model.FFCUser) bool

IsEnable alias of boolVariation for a given user @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Return if the flag should be enabled, or false if the flag is disabled, or an error occurs

func (*Client) IsFlagKnown

func (c *Client) IsFlagKnown(featureFlagKey string) bool

IsFlagKnown Returns true if the specified feature flag currently exists. @Param featureFlagKey the unique key for the feature flag @Return true if the flag exists

func (*Client) IsInitialized

func (c *Client) IsInitialized() bool

IsInitialized Tests whether the client is ready to be used. @Return true if the client is ready, or false if it is still initializing

func (*Client) TrackMetric

func (c *Client) TrackMetric(user model.FFCUser, eventName string)

TrackMetric tracks that a user performed an event and provides a default numeric value for custom metrics @Param user the user that performed the event @Param eventName the name of the event

func (*Client) TrackMetricSeries

func (c *Client) TrackMetricSeries(user model.FFCUser, metrics map[string]float64)

TrackMetricSeries tracks that a user performed an event and provides a default numeric value for custom metrics @Param user the user that performed the event @Param metrics event name and numeric value in K/V

func (*Client) TrackMetricWithValue

func (c *Client) TrackMetricWithValue(user model.FFCUser, eventName string, metricValue float64)

TrackMetricWithValue tracks that a user performed an event and provides a default numeric value for custom metrics @Param user the user that performed the event @Param eventName the name of the event @Param metricValue a numeric value used by the experimentation feature in numeric custom metrics.

func (*Client) TrackMetrics

func (c *Client) TrackMetrics(user model.FFCUser, eventNames ...string)

TrackMetrics tracks that a user performed an event and provides a default numeric value for custom metrics @Param user the user that performed the event @Param eventName the name of the events

func (*Client) Variation

func (c *Client) Variation(featureFlagKey string, user model.FFCUser, defaultValue string) string

Variation Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

func (*Client) VariationDetail

func (c *Client) VariationDetail(featureFlagKey string, user model.FFCUser, defaultValue string) model.FlagState

VariationDetail Calculates the value of a feature flag for a given user. @Param featureFlagKey the unique key for the feature flag @Param user the end user requesting the flag @Param defaultValue the default value of the flag @Return the variation for the given user, or defaultValue if the flag is disabled or an error occurs

type Config

type Config struct {
	StartWaitTime           time.Duration
	OffLine                 bool
	HttpConfig              HttpConfig
	UpdateProcessorFactory  UpdateProcessorFactory
	InsightProcessorFactory InsightProcessorFactory
	HttpConfigFactory       HttpConfigFactory
}

type ConfigBuilder

type ConfigBuilder struct {
	StartWaitTime           time.Duration
	UpdateProcessorFactory  UpdateProcessorFactory
	InsightProcessorFactory InsightProcessorFactory
	HttpConfigFactory       HttpConfigFactory
	Offline                 bool
}

ConfigBuilder build data for config object

func NewConfigBuilder

func NewConfigBuilder() *ConfigBuilder

func (*ConfigBuilder) Build

func (c *ConfigBuilder) Build() *Config

func (*ConfigBuilder) SetHttpConfigFactory

func (c *ConfigBuilder) SetHttpConfigFactory(httpConfigFactory HttpConfigFactory) *ConfigBuilder

func (*ConfigBuilder) SetInsightProcessorFactory

func (c *ConfigBuilder) SetInsightProcessorFactory(insightProcessorFactory InsightProcessorFactory) *ConfigBuilder

func (*ConfigBuilder) SetOffline

func (c *ConfigBuilder) SetOffline(offline bool) *ConfigBuilder

func (*ConfigBuilder) SetStartWaitTime

func (c *ConfigBuilder) SetStartWaitTime(startWaitTime time.Duration) *ConfigBuilder

func (*ConfigBuilder) SetUpdateProcessorFactory

func (c *ConfigBuilder) SetUpdateProcessorFactory(streamingBuilder *StreamingBuilder) *ConfigBuilder

type Context

type Context struct {
	HttpConfig  HttpConfig
	BasicConfig BasicConfig
}

func NewContext

func NewContext(envSecret string, config *Config) Context

NewContext create Context object @Param envSecret @Param config @Return a Context object

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

func NewEvaluator

func NewEvaluator(dataStorage data.DataStorage) Evaluator

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(flag data.FeatureFlag, user model.FFCUser, event data.Event) *data.EvalResult

type HttpConfig

type HttpConfig struct {
	ConnectTime     time.Duration
	SocketTime      time.Duration
	Headers         map[string]string
	TLSClientConfig *tls.Config
	Proxy           func(*http.Request) (*url.URL, error)
}

type HttpConfigBuilder

type HttpConfigBuilder struct {
	Proxy           func(*http.Request) (*url.URL, error)
	ConnectTime     time.Duration
	SocketTime      time.Duration
	TLSClientConfig *tls.Config
}

func HttpConfigBuilderFactory

func HttpConfigBuilderFactory() *HttpConfigBuilder

func NewHttpConfigBuilder

func NewHttpConfigBuilder() *HttpConfigBuilder

func (*HttpConfigBuilder) CreateHttpConfig

func (h *HttpConfigBuilder) CreateHttpConfig(config BasicConfig) HttpConfig

func (*HttpConfigBuilder) SetConnectTime

func (h *HttpConfigBuilder) SetConnectTime(connectTime time.Duration) *HttpConfigBuilder

func (*HttpConfigBuilder) SetHttpProxy

func (h *HttpConfigBuilder) SetHttpProxy(proxyHost string, proxyPort int) *HttpConfigBuilder

func (*HttpConfigBuilder) SetSSlConfig

func (h *HttpConfigBuilder) SetSSlConfig(config *tls.Config) *HttpConfigBuilder

func (*HttpConfigBuilder) SetSocketTime

func (h *HttpConfigBuilder) SetSocketTime(socketTime time.Duration) *HttpConfigBuilder

type HttpConfigFactory

type HttpConfigFactory interface {
	// CreateHttpConfig Creates the http configuration.
	// @Param config provides the basic SDK configuration properties
	// @Return an HttpConfig instance
	CreateHttpConfig(config BasicConfig) HttpConfig
}

type Insight

type Insight struct {
	InsightConfig InsightConfig
	// contains filtered or unexported fields
}

func NewInsight

func NewInsight(config InsightConfig) Insight

func (*Insight) Flush

func (i *Insight) Flush()

func (*Insight) Send

func (i *Insight) Send(event data.Event)

type InsightBuilder

type InsightBuilder struct {
	MaxRetryTimes int
	RetryInterval int // Millisecond
	HttpConfig    HttpConfig
	EventUri      string
	Capacity      float64
}

func InsightBuilderFactory

func InsightBuilderFactory() *InsightBuilder

func NewInsightBuilder

func NewInsightBuilder() *InsightBuilder

func (*InsightBuilder) CreateInsightProcessor

func (i *InsightBuilder) CreateInsightProcessor(context Context) InsightProcessor

func (*InsightBuilder) SetCapacity

func (i *InsightBuilder) SetCapacity(capacity float64) *InsightBuilder

func (*InsightBuilder) SetEventUri

func (i *InsightBuilder) SetEventUri(eventUri string) *InsightBuilder

func (*InsightBuilder) SetMaxRetryTimes

func (i *InsightBuilder) SetMaxRetryTimes(maxRetryTimes int) *InsightBuilder

func (*InsightBuilder) SetRetryInterval

func (i *InsightBuilder) SetRetryInterval(retryInterval int) *InsightBuilder

type InsightConfig

type InsightConfig struct {
	EventUrl      string
	FlushInterval int64
	Capacity      int
	// contains filtered or unexported fields
}

func NewInsightConfig

func NewInsightConfig(sender InsightEventSender, baseUri string, flushInterval int64, capacity int) InsightConfig

type InsightEvent

type InsightEvent struct {
	MaxRetryTimes int
	RetryInterval int
	HttpConfig    HttpConfig
}

func NewInsightEvent

func NewInsightEvent(config HttpConfig, maxRetryTimes int, retryInterval int) *InsightEvent

func (*InsightEvent) PostJson

func (i *InsightEvent) PostJson(url string, jsonData string, retryTimes int, retryInterval int) string

func (*InsightEvent) PostJsonWithHeaders

func (i *InsightEvent) PostJsonWithHeaders(url string, jsonData string, retryTimes int,
	retryInterval int) string

func (*InsightEvent) SendEvent

func (i *InsightEvent) SendEvent(eventUrl string, json string)

type InsightEventSender

type InsightEventSender interface {
	SendEvent(eventUrl string, json string)
}

type InsightProcessor

type InsightProcessor interface {

	// Send  Records an event asynchronously.
	Send(event data.Event)

	// Flush Specifies that any buffered events should be sent as soon as possible, rather than waiting
	// for the next flush interval. This method is asynchronous, so events still may not be sent
	// until a later time.
	Flush()
}

type InsightProcessorFactory

type InsightProcessorFactory interface {

	// CreateInsightProcessor creates an implementation of {@link InsightProcessor}
	CreateInsightProcessor(context Context) InsightProcessor
}

type NullUpdateProcessor

type NullUpdateProcessor struct {
}

func (*NullUpdateProcessor) IsInitialized

func (n *NullUpdateProcessor) IsInitialized() bool

func (*NullUpdateProcessor) Start

func (n *NullUpdateProcessor) Start() bool

type NullUpdateProcessorFactory

type NullUpdateProcessorFactory struct {
}

func (*NullUpdateProcessorFactory) CreateUpdateProcessor

func (n *NullUpdateProcessorFactory) CreateUpdateProcessor(context Context) UpdateProcessor

type Streaming

type Streaming struct {
	BasicConfig  BasicConfig
	HttpConfig   HttpConfig
	StreamingURL string
}

func NewStreaming

func NewStreaming(config Context, streamingURI string) *Streaming

func (*Streaming) Connect

func (s *Streaming) Connect()

func (*Streaming) IsInitialized

func (s *Streaming) IsInitialized() bool

func (*Streaming) PingOrDataSync

func (s *Streaming) PingOrDataSync(stime *time.Time, msgType string)

PingOrDataSync websocket ping

func (*Streaming) Start

func (s *Streaming) Start() bool

type StreamingBuilder

type StreamingBuilder struct {
	StreamingURI    string
	FirstRetryDelay time.Duration
	MaxRetryTimes   int64
}

func NewStreamingBuilder

func NewStreamingBuilder() *StreamingBuilder

func StreamingBuilderFactory

func StreamingBuilderFactory() *StreamingBuilder

func (*StreamingBuilder) CreateUpdateProcessor

func (s *StreamingBuilder) CreateUpdateProcessor(context Context) UpdateProcessor

func (*StreamingBuilder) NewDefaultStreamingURI

func (s *StreamingBuilder) NewDefaultStreamingURI() *StreamingBuilder

func (*StreamingBuilder) NewStreamingURI

func (s *StreamingBuilder) NewStreamingURI(uri string) *StreamingBuilder

func (*StreamingBuilder) SetFirstRetryDelay

func (s *StreamingBuilder) SetFirstRetryDelay(duration time.Duration) *StreamingBuilder

func (*StreamingBuilder) SetMaxRetryTimes

func (s *StreamingBuilder) SetMaxRetryTimes(maxRetryTimes int64) *StreamingBuilder

type UpdateProcessor

type UpdateProcessor interface {

	// Start Starts the client update processing.
	// @return completion status indicates the client has been initialized.
	Start() bool

	// IsInitialized Returns true once the client has been initialized and will never return false again.
	// @return true if the client has been initialized
	IsInitialized() bool
}

type UpdateProcessorFactory

type UpdateProcessorFactory interface {

	// CreateUpdateProcessor Creates an implementation instance.
	// @param context allows access to the client configuration
	// @return an {@link UpdateProcessor}
	CreateUpdateProcessor(context Context) UpdateProcessor
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL