client

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 28 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptySDKKeyError              = errors.New("default variation was returned")
	DefaultVariationReturnedError = errors.New("default variation was returned")
	FetchFlagsError               = errors.New("fetching flags failed")
)

Functions

func NewCustomTransport added in v0.1.16

func NewCustomTransport(baseTransport http.RoundTripper, getHeaderFn HeadersFn) *customTransport

Types

type CfClient

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

CfClient is the Feature Flag client.

This object evaluates feature flags and communicates with Feature Flag services. Applications should instantiate a single instance for the lifetime of their application and share it wherever feature flags need to be evaluated.

When an application is shutting down or no longer needs to use the CfClient instance, it should call Close() to ensure that all of its connections and goroutines are shut down and that any pending analytics events have been delivered.

func NewCfClient

func NewCfClient(sdkKey string, options ...ConfigOption) (*CfClient, error)

NewCfClient creates a new client instance that connects to CF with the default configuration. For advanced configuration options use ConfigOptions functions

func (*CfClient) BoolVariation

func (c *CfClient) BoolVariation(key string, target *evaluation.Target, defaultValue bool) (bool, error)

BoolVariation returns the value of a boolean feature flag for a given target. Returns defaultValue if there is an error or if the flag doesn't exist

func (*CfClient) Close

func (c *CfClient) Close() error

Close shuts down the Feature Flag client. After calling this, the client should no longer be used

func (*CfClient) Environment

func (c *CfClient) Environment() string

Environment returns environment based on authenticated SDK flagIdentifier

func (*CfClient) GetClusterIdentifier added in v0.0.25

func (c *CfClient) GetClusterIdentifier() string

GetClusterIdentifier returns the cluster identifier we're connected to

func (*CfClient) IntVariation

func (c *CfClient) IntVariation(key string, target *evaluation.Target, defaultValue int64) (int64, error)

IntVariation returns the value of a integer feature flag for a given target.

Returns defaultValue if there is an error or if the flag doesn't exist

func (*CfClient) InterceptAddCluster

func (c *CfClient) InterceptAddCluster(ctx context.Context, req *http.Request) error

InterceptAddCluster adds cluster ID to calls

func (*CfClient) IsInitialized

func (c *CfClient) IsInitialized() (bool, error)

IsInitialized determines if the client is ready to be used. This is true if it has both authenticated and successfully retrieved flags. If it takes longer than 1 minute the call will timeout and return an error.

func (*CfClient) IsStreamConnected added in v0.0.24

func (c *CfClient) IsStreamConnected() bool

IsStreamConnected determines if the stream is currently connected

func (*CfClient) JSONVariation

func (c *CfClient) JSONVariation(key string, target *evaluation.Target, defaultValue types.JSON) (types.JSON, error)

JSONVariation returns the value of a feature flag for the given target, allowing the value to be of any JSON type.

Returns defaultValue if there is an error or if the flag doesn't exist

func (*CfClient) NumberVariation

func (c *CfClient) NumberVariation(key string, target *evaluation.Target, defaultValue float64) (float64, error)

NumberVariation returns the value of a float64 feature flag for a given target.

Returns defaultValue if there is an error or if the flag doesn't exist

func (*CfClient) PostEvaluateProcessor added in v0.0.25

func (c *CfClient) PostEvaluateProcessor(data *evaluation.PostEvalData)

PostEvaluateProcessor push the data to the analytics service

func (*CfClient) StringVariation

func (c *CfClient) StringVariation(key string, target *evaluation.Target, defaultValue string) (string, error)

StringVariation returns the value of a string feature flag for a given target.

Returns defaultValue if there is an error or if the flag doesn't exist

type ConfigOption

type ConfigOption func(config *config)

ConfigOption is used as return value for advanced client configuration using options pattern

func WithAnalyticsEnabled added in v0.1.2

func WithAnalyticsEnabled(val bool) ConfigOption

WithAnalyticsEnabled en/disable cache and analytics data being sent.

func WithAuthRetryStrategy added in v0.1.16

func WithAuthRetryStrategy(retryStrategy *backoff.ExponentialBackOff) ConfigOption

WithAuthRetryStrategy sets the backoff and retry strategy for client authentication requests Mainly used for testing purposes, as the SDKs default backoff strategy should be sufficient for most if not all scenarios.

func WithCache

func WithCache(cache cache.Cache) ConfigOption

WithCache set custom cache or predefined one from cache package

func WithEventStreamListener added in v0.0.24

func WithEventStreamListener(e stream.EventStreamListener) ConfigOption

WithEventStreamListener configures the SDK to forward Events from the Feature Flag server to the passed EventStreamListener

func WithEventsURL

func WithEventsURL(url string) ConfigOption

WithEventsURL set eventsURL for communicating with ff server

func WithHTTPClient

func WithHTTPClient(client *http.Client) ConfigOption

WithHTTPClient set auth and http client for use in interactions with ff server

func WithLogger

func WithLogger(logger logger.Logger) ConfigOption

WithLogger set custom logger used in main application

func WithMaxAuthRetries added in v0.1.12

func WithMaxAuthRetries(i int) ConfigOption

WithMaxAuthRetries sets how many times the SDK will retry if authentication fails

func WithProxyMode added in v0.1.9

func WithProxyMode(b bool) ConfigOption

WithProxyMode should be used when the SDK is being used inside the ff proxy to control the cache and handle sse events

func WithPullInterval

func WithPullInterval(interval uint) ConfigOption

WithPullInterval set pulling interval in minutes

func WithSleeper added in v0.1.12

func WithSleeper(sleeper types.Sleeper) ConfigOption

WithSleeper is used to aid in testing functionality that sleeps

func WithStore

func WithStore(store storage.Storage) ConfigOption

WithStore set custom storage or predefined one from storage package

func WithStoreEnabled

func WithStoreEnabled(val bool) ConfigOption

WithStoreEnabled set store on or off

func WithStreamEnabled

func WithStreamEnabled(val bool) ConfigOption

WithStreamEnabled set stream on or off

func WithTarget

func WithTarget(target evaluation.Target) ConfigOption

WithTarget sets target

func WithURL

func WithURL(url string) ConfigOption

WithURL set baseUrl for communicating with ff server

func WithWaitForInitialized added in v0.1.12

func WithWaitForInitialized(b bool) ConfigOption

WithWaitForInitialized configures the SDK to block the thread until initialization succeeds or fails

type HeadersFn added in v0.1.16

type HeadersFn func(r *http.Request) (map[string]string, error)

HeadersFn is a function type that provides headers dynamically.

type InitializeTimeoutError added in v0.1.12

type InitializeTimeoutError struct {
}

func (InitializeTimeoutError) Error added in v0.1.12

func (e InitializeTimeoutError) Error() string

type NonRetryableAuthError added in v0.1.12

type NonRetryableAuthError struct {
	StatusCode string
	Message    string
}

func (NonRetryableAuthError) Error added in v0.1.12

func (e NonRetryableAuthError) Error() string

type RetryableAuthError added in v0.1.12

type RetryableAuthError struct {
	StatusCode string
	Message    string
}

func (RetryableAuthError) Error added in v0.1.12

func (e RetryableAuthError) Error() string

Jump to

Keyboard shortcuts

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