Documentation
¶
Index ¶
- Constants
- func WithEvaluationContext(ctx context.Context, ec EvaluationContext) context.Context
- type AnalyticsProcessor
- type Client
- func (c *Client) BulkIdentify(ctx context.Context, batch []*IdentityTraits) error
- func (c *Client) GetEnvironmentFlags(ctx context.Context) (f Flags, err error)deprecated
- func (c *Client) GetEnvironmentFlagsFromAPI(ctx context.Context) (Flags, error)
- func (c *Client) GetFlags(ctx context.Context, ec *EvaluationContext) (f Flags, err error)
- func (c *Client) GetIdentityFlags(ctx context.Context, identifier string, traits []*Trait) (f Flags, err error)deprecated
- func (c *Client) GetIdentityFlagsFromAPI(ctx context.Context, identifier string, traits []*Trait) (Flags, error)
- func (c *Client) GetIdentitySegments(identifier string, traits []*Trait) ([]*segments.SegmentModel, error)
- func (c *Client) UpdateEnvironment(ctx context.Context) error
- type EnvironmentEvaluationContext
- type EvaluationContext
- type FeatureEvaluationContext
- type Flag
- type Flags
- type FlagsmithAPIError
- type FlagsmithClientError
- type IdentityEvaluationContext
- type IdentityTraits
- type LocalFileHandler
- type Logger
- type OfflineHandler
- type Option
- func WithAnalytics(ctx context.Context) Option
- func WithBaseURL(url string) Option
- func WithCustomHeaders(headers map[string]string) Option
- func WithDefaultHandler(handler func(string) (Flag, error)) Option
- func WithEnvironmentRefreshInterval(interval time.Duration) Option
- func WithErrorHandler(handler func(handler *FlagsmithAPIError)) Option
- func WithLocalEvaluation(ctx context.Context) Option
- func WithLogger(logger Logger) Option
- func WithOfflineHandler(handler OfflineHandler) Option
- func WithOfflineMode() Option
- func WithPolling() Option
- func WithProxy(proxyURL string) Option
- func WithRealtime() Option
- func WithRealtimeBaseURL(url string) Option
- func WithRemoteEvaluation() Option
- func WithRequestTimeout(timeout time.Duration) Option
- func WithRetries(count int, waitTime time.Duration) Option
- func WithSlogLogger(logger *slog.Logger) Option
- type Trait
- type TraitEvaluationContext
Constants ¶
const ( // Number of seconds to wait for a request to // complete before terminating the request. DefaultTimeout = 10 * time.Second // Default base URL for the API. DefaultBaseURL = "https://edge.api.flagsmith.com/api/v1/" BulkIdentifyMaxCount = 100 DefaultRealtimeBaseUrl = "https://realtime.flagsmith.com/" )
const AnalyticsEndpoint = "analytics/flags/"
const AnalyticsTimerInMilli = 10 * 1000
const EnvironmentKeyHeader = "X-Environment-Key"
Variables ¶
This section is empty.
Functions ¶
func WithEvaluationContext ¶
func WithEvaluationContext(ctx context.Context, ec EvaluationContext) context.Context
Returns context with provided EvaluationContext instance set.
Types ¶
type AnalyticsProcessor ¶
type AnalyticsProcessor struct {
// contains filtered or unexported fields
}
func NewAnalyticsProcessor ¶
func (*AnalyticsProcessor) TrackFeature ¶
func (a *AnalyticsProcessor) TrackFeature(featureName string)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides various methods to query Flagsmith API.
func (*Client) BulkIdentify ¶
func (c *Client) BulkIdentify(ctx context.Context, batch []*IdentityTraits) error
BulkIdentify can be used to create/overwrite identities(with traits) in bulk NOTE: This method only works with Edge API endpoint.
func (*Client) GetEnvironmentFlags
deprecated
Returns `Flags` struct holding all the flags for the current environment.
If local evaluation is enabled this function will not call the Flagsmith API directly, but instead read the asynchronously updated local environment or use the default flag handler in case it has not yet been updated.
Deprecated: Use `GetFlags` instead.
func (*Client) GetEnvironmentFlagsFromAPI ¶
GetEnvironmentFlagsFromAPI tries to contact the Flagsmith API to get the latest environment data. Will return an error in case of failure or unexpected response.
func (*Client) GetFlags ¶
Returns `Flags` struct holding all the flags for the current environment.
Provide `EvaluationContext` to evaluate flags for a specific environment or identity.
If local evaluation is enabled this function will not call the Flagsmith API directly, but instead read the asynchronously updated local environment or use the default flag handler in case it has not yet been updated.
Notes:
* `EvaluationContext.Environment` is ignored in local evaluation mode.
* `EvaluationContext.Feature` is not yet supported.
func (*Client) GetIdentityFlags
deprecated
func (c *Client) GetIdentityFlags(ctx context.Context, identifier string, traits []*Trait) (f Flags, err error)
Returns `Flags` struct holding all the flags for the current environment for a given identity.
If local evaluation is disabled it will also upsert all traits to the Flagsmith API for future evaluations. Providing a trait with a value of nil will remove the trait from the identity if it exists.
If local evaluation is enabled this function will not call the Flagsmith API directly, but instead read the asynchronously updated local environment or use the default flag handler in case it has not yet been updated.
Deprecated: Use `GetFlags` providing `EvaluationContext.Identity` instead.
func (*Client) GetIdentityFlagsFromAPI ¶
func (c *Client) GetIdentityFlagsFromAPI(ctx context.Context, identifier string, traits []*Trait) (Flags, error)
GetIdentityFlagsFromAPI tries to contact the Flagsmith API to get the latest identity flags. Will return an error in case of failure or unexpected response.
func (*Client) GetIdentitySegments ¶
func (c *Client) GetIdentitySegments(identifier string, traits []*Trait) ([]*segments.SegmentModel, error)
Returns an array of segments that the given identity is part of.
type EnvironmentEvaluationContext ¶
type EnvironmentEvaluationContext struct {
APIKey string `json:"api_key"`
}
type EvaluationContext ¶
type EvaluationContext struct {
Environment *EnvironmentEvaluationContext `json:"environment,omitempty"`
Feature *FeatureEvaluationContext `json:"feature,omitempty"`
Identity *IdentityEvaluationContext `json:"identity,omitempty"`
}
func GetEvaluationContextFromCtx ¶
func GetEvaluationContextFromCtx(ctx context.Context) (ec EvaluationContext, ok bool)
Retrieve EvaluationContext instance from context.
func NewEvaluationContext ¶
func NewEvaluationContext(identifier string, traits map[string]interface{}) EvaluationContext
func NewTransientEvaluationContext ¶
func NewTransientEvaluationContext(identifier string, traits map[string]interface{}) EvaluationContext
type FeatureEvaluationContext ¶
type FeatureEvaluationContext struct {
Name string `json:"name"`
}
type Flags ¶
type Flags struct {
// contains filtered or unexported fields
}
func (*Flags) GetFeatureValue ¶
Returns the value of a particular flag.
type FlagsmithAPIError ¶
func (FlagsmithAPIError) Error ¶
func (e FlagsmithAPIError) Error() string
type FlagsmithClientError ¶
type FlagsmithClientError struct {
// contains filtered or unexported fields
}
func (FlagsmithClientError) Error ¶
func (e FlagsmithClientError) Error() string
type IdentityEvaluationContext ¶
type IdentityEvaluationContext struct {
Identifier *string `json:"identifier,omitempty"`
Traits map[string]*TraitEvaluationContext `json:"traits,omitempty"`
Transient *bool `json:"transient,omitempty"`
}
type IdentityTraits ¶
type LocalFileHandler ¶
type LocalFileHandler struct {
// contains filtered or unexported fields
}
func NewLocalFileHandler ¶
func NewLocalFileHandler(environmentDocumentPath string) (*LocalFileHandler, error)
NewLocalFileHandler creates a new LocalFileHandler with the given path.
func (*LocalFileHandler) GetEnvironment ¶
func (handler *LocalFileHandler) GetEnvironment() *environments.EnvironmentModel
type Logger ¶
type Logger interface {
// Errorf logs an error message with the given format and arguments.
Errorf(format string, v ...interface{})
// Warnf logs a warning message with the given format and arguments.
Warnf(format string, v ...interface{})
// Debugf logs a debug message with the given format and arguments.
Debugf(format string, v ...interface{})
}
Logger is the interface used for logging by flagsmith client. This interface defines the methods that a logger implementation must implement. It is used to abstract logging and enable clients to use any logger implementation they want.
type OfflineHandler ¶
type OfflineHandler interface {
GetEnvironment() *environments.EnvironmentModel
}
type Option ¶
type Option func(c *Client)
func WithAnalytics ¶
WithAnalytics enables tracking of the usage of the Feature flags.
The goroutine responsible for asynchronously uploading the locally stored cache uses the context provided here, which means that if it expires the background process will exit.
func WithBaseURL ¶
func WithCustomHeaders ¶
func WithErrorHandler ¶
func WithErrorHandler(handler func(handler *FlagsmithAPIError)) Option
WithErrorHandler provides a way to handle errors that occur during update of an environment.
func WithLocalEvaluation ¶
WithLocalEvaluation enables local evaluation of the Feature flags.
The goroutine responsible for asynchronously updating the environment makes use of the context provided here, which means that if it expires the background process will exit.
func WithLogger ¶
Allows the client to use any logger that implements the `Logger` interface.
func WithOfflineHandler ¶
func WithOfflineHandler(handler OfflineHandler) Option
WithOfflineHandler returns an Option function that sets the offline handler.
func WithOfflineMode ¶
func WithOfflineMode() Option
WithOfflineMode returns an Option function that enables the offline mode. NOTE: before using this option, you should set the offline handler.
func WithPolling ¶ added in v4.2.0
func WithPolling() Option
WithPolling makes it so that the client will poll for updates even when WithRealtime is used.
func WithProxy ¶
WithProxy returns an Option function that sets the proxy(to be used by internal resty client). The proxyURL argument is a string representing the URL of the proxy server to use, e.g. "http://proxy.example.com:8080".
func WithRealtime ¶ added in v4.1.0
func WithRealtime() Option
WithRealtime returns an Option function that enables real-time updates for the Client. NOTE: Before enabling real-time updates, ensure that local evaluation is enabled.
func WithRealtimeBaseURL ¶ added in v4.1.0
WithRealtimeBaseURL returns an Option function for configuring the real-time base URL of the Client.
func WithRemoteEvaluation ¶
func WithRemoteEvaluation() Option
func WithRequestTimeout ¶
func WithSlogLogger ¶ added in v4.2.0
WithSlogLogger allows the client to use a slog.Logger for logging.
type Trait ¶
type Trait struct {
TraitKey string `json:"trait_key"`
TraitValue interface{} `json:"trait_value"`
Transient bool `json:"transient,omitempty"`
}
func (*Trait) ToTraitModel ¶
func (t *Trait) ToTraitModel() *traits.TraitModel
type TraitEvaluationContext ¶
type TraitEvaluationContext struct {
Transient *bool `json:"transient,omitempty"`
Value interface{} `json:"value"`
}
func NewTraitEvaluationContext ¶
func NewTraitEvaluationContext(value interface{}, transient bool) TraitEvaluationContext