interfaces

package
v6.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

Package interfaces contains types that are part of the public API, but not needed for basic use of the SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationInfo

type ApplicationInfo struct {
	// ApplicationID is a unique identifier representing the application where the LaunchDarkly SDK is
	// running.
	//
	// This can be specified as any string value as long as it only uses the following characters: ASCII
	// letters, ASCII digits, period, hyphen, underscore. A string containing any other characters will be
	// ignored.
	ApplicationID string

	// ApplicationVersion is a unique identifier representing the version of the application where the
	// LaunchDarkly SDK is running.
	//
	// This can be specified as any string value as long as it only uses the following characters: ASCII
	// letters, ASCII digits, period, hyphen, underscore. A string containing any other characters will be
	// ignored.
	ApplicationVersion string
}

ApplicationInfo allows configuration of application metadata.

Application metadata may be used in LaunchDarkly analytics or other product features, but does not affect feature flag evaluations.

If you want to set non-default values for any of these fields, set the ApplicationInfo field in the SDK's github.com/launchdarkly/go-server-sdk/v6.Config struct.

type BigSegmentStoreStatus

type BigSegmentStoreStatus struct {
	// Available is true if the Big Segment store is able to respond to queries, so that the SDK can
	// evaluate whether an evaluation context is in a segment or not.
	//
	// If this property is false, the store is not able to make queries (for instance, it may not have
	// a valid database connection). In this case, the SDK will treat any reference to a Big Segment
	// as if no contexts are included in that segment. Also, the EvaluationReason associated with any
	// flag evaluation that references a Big Segment when the store is not available will return
	// ldreason.BigSegmentsStoreError from its GetBigSegmentsStatus() method.
	Available bool

	// Stale is true if the Big Segment store is available, but has not been updated within the amount
	// of time specified by BigSegmentsConfigurationBuilder.StaleTime(). This may indicate that the
	// LaunchDarkly Relay Proxy, which populates the store, has stopped running or has become unable
	// to receive fresh data from LaunchDarkly. Any feature flag evaluations that reference a Big
	// Segment will be using the last known data, which may be out of date.
	Stale bool
}

BigSegmentStoreStatus contains information about the status of a Big Segment store, provided by BigSegmentStoreStatusProvider.

"Big Segments" are a specific type of user segments. For more information, read the LaunchDarkly documentation about user segments: https://docs.launchdarkly.com/home/users

type BigSegmentStoreStatusProvider

type BigSegmentStoreStatusProvider interface {
	// GetStatus returns the current status of the store.
	GetStatus() BigSegmentStoreStatus

	// AddStatusListener subscribes for notifications of status changes. The returned channel will receive a
	// new BigSegmentStoreStatus value for any change in status.
	//
	// Applications may wish to know if there is an outage in the Big Segment store, or if it has become stale
	// (the Relay Proxy has stopped updating it with new data), since then flag evaluations that reference a
	// Big Segment might return incorrect values.
	//
	// If the SDK receives an exception while trying to query the Big Segment store, then it publishes a
	// BigSegmentStoreStatus where Available is false, to indicate that the store appears to be offline. Once
	// it is successful in querying the store's status, it publishes a new status where Available is true.
	//
	// It is the caller's responsibility to consume values from the channel. Allowing values to accumulate in
	// the channel can cause an SDK goroutine to be blocked. If you no longer need the channel, call
	// RemoveStatusListener.
	AddStatusListener() <-chan BigSegmentStoreStatus

	// RemoveStatusListener unsubscribes from notifications of status changes. The specified channel must be
	// one that was previously returned by AddStatusListener(); otherwise, the method has no effect.
	RemoveStatusListener(<-chan BigSegmentStoreStatus)
}

BigSegmentStoreStatusProvider is an interface for querying the status of a Big Segment store. The Big Segment store is the component that receives information about Big Segments, normally from a database populated by the LaunchDarkly Relay Proxy.

"Big Segments" are a specific type of user segments. For more information, read the LaunchDarkly documentation about user segments: https://docs.launchdarkly.com/home/users

An implementation of this interface is returned by github.com/launchdarkly/go-server-sdk/v6.LDClient.GetBigSegmentStoreStatusProvider. Application code should not implement this interface.

There are two ways to interact with the status. One is to simply get the current status; if its Available property is true, then the SDK is able to evaluate context membership in Big Segments, the Stale property indicates whether the data might be out of date.

status := client.GetBigSegmentStoreStatusProvider().GetStatus()

Second, you can use AddStatusListener to get a channel that provides a status update whenever the Big Segment store has an error or starts working again.

statusCh := client.GetBigSegmentStoreStatusProvider().AddStatusListener()
go func() {
    for newStatus := range statusCh {
        log.Printf("Big Segment store status is now: %+v", newStatus)
    }
}()

type DataSourceErrorInfo

type DataSourceErrorInfo struct {
	// Kind is the general category of the error. It will always be one of the DataSourceErrorKind
	// constants such as DataSourceErrorKindNetworkError, or "" if there have not been any errors.
	Kind DataSourceErrorKind

	// StatusCode is the HTTP status code if the error was DataSourceErrorKindErrorResponse, or zero
	// otherwise.
	StatusCode int

	// Message is any any additional human-readable information relevant to the error. The format of
	// this message is subject to change and should not be relied on programmatically.
	Message string

	// Time is the date/time that the error occurred.
	Time time.Time
}

DataSourceErrorInfo is a description of an error condition that the data source encountered.

See DataSourceStatusProvider.

func (DataSourceErrorInfo) String

func (e DataSourceErrorInfo) String() string

String returns a simple string representation of the error.

type DataSourceErrorKind

type DataSourceErrorKind string

DataSourceErrorKind is any of the allowable values for DataSourceErrorInfo.Kind.

See DataSourceStatusProvider.

const (
	// DataSourceErrorKindUnknown indicates an unexpected error, such as an uncaught exception,
	// further described by DataSourceErrorInfo.Message.
	DataSourceErrorKindUnknown DataSourceErrorKind = "UNKNOWN"

	// DataSourceErrorKindNetworkError represents an I/O error such as a dropped connection.
	DataSourceErrorKindNetworkError DataSourceErrorKind = "NETWORK_ERROR"

	// DataSourceErrorKindErrorResponse means the LaunchDarkly service returned an HTTP response
	// with an error status, available in DataSourceErrorInfo.StatusCode.
	DataSourceErrorKindErrorResponse DataSourceErrorKind = "ERROR_RESPONSE"

	// DataSourceErrorKindInvalidData means the SDK received malformed data from the LaunchDarkly
	// service.
	DataSourceErrorKindInvalidData DataSourceErrorKind = "INVALID_DATA"

	// DataSourceErrorKindStoreError means the data source itself is working, but when it tried
	// to put an update into the data store, the data store failed (so the SDK may not have the
	// latest data).
	//
	// Data source implementations do not need to report this kind of error; it will be
	// automatically reported by the SDK whenever one of the update methods of DataSourceUpdateSink
	// encounters a failure.
	DataSourceErrorKindStoreError DataSourceErrorKind = "STORE_ERROR"
)

type DataSourceState

type DataSourceState string

DataSourceState is any of the allowable values for DataSourceStatus.State.

See DataSourceStatusProvider.

const (
	// DataSourceStateInitializing is the initial state of the data source when the SDK is being
	// initialized.
	//
	// If it encounters an error that requires it to retry initialization, the state will remain at
	// Initializing until it either succeeds and becomes DataSourceStateValid, or permanently fails and
	// becomes DataSourceStateOff.
	DataSourceStateInitializing DataSourceState = "INITIALIZING"

	// DataSourceStateValid indicates that the data source is currently operational and has not had
	// any problems since the last time it received data.
	//
	// In streaming mode, this means that there is currently an open stream connection and that at least
	// one initial message has been received on the stream. In polling mode, it means that the last poll
	// request succeeded.
	DataSourceStateValid DataSourceState = "VALID"

	// DataSourceStateInterrupted indicates that the data source encountered an error that it will
	// attempt to recover from.
	//
	// In streaming mode, this means that the stream connection failed, or had to be dropped due to some
	// other error, and will be retried after a backoff delay. In polling mode, it means that the last poll
	// request failed, and a new poll request will be made after the configured polling interval.
	DataSourceStateInterrupted DataSourceState = "INTERRUPTED"

	// DataSourceStateOff indicates that the data source has been permanently shut down.
	//
	// This could be because it encountered an unrecoverable error (for instance, the LaunchDarkly service
	// rejected the SDK key; an invalid SDK key will never become valid), or because the SDK client was
	// explicitly shut down.
	DataSourceStateOff DataSourceState = "OFF"
)

type DataSourceStatus

type DataSourceStatus struct {
	// State represents the overall current state of the data source. It will always be one of the
	// DataSourceState constants such as DataSourceStateValid.
	State DataSourceState

	// StateSince is the date/time that the value of State most recently changed.
	//
	// The meaning of this depends on the current State:
	//   - For DataSourceStateInitializing, it is the time that the SDK started initializing.
	//   - For DataSourceStateValid, it is the time that the data source most recently entered a valid
	//     state, after previously having been either Initializing or Interrupted.
	//   - For DataSourceStateInterrupted, it is the time that the data source most recently entered an
	//     error state, after previously having been Valid.
	//   - For DataSourceStateOff, it is the time that the data source encountered an unrecoverable error
	//     or that the SDK was explicitly shut down.
	StateSince time.Time

	// LastError is information about the last error that the data source encountered, if any.
	//
	// This property should be updated whenever the data source encounters a problem, even if it does
	// not cause State to change. For instance, if a stream connection fails and the
	// state changes to DataSourceStateInterrupted, and then subsequent attempts to restart the
	// connection also fail, the state will remain Interrupted but the error information
	// will be updated each time-- and the last error will still be reported in this property even if
	// the state later becomes Valid.
	//
	// If no error has ever occurred, this field will be an empty DataSourceErrorInfo{}.
	LastError DataSourceErrorInfo
}

DataSourceStatus is information about the data source's status and the last status change.

See DataSourceStatusProvider.

func (DataSourceStatus) String

func (e DataSourceStatus) String() string

String returns a simple string representation of the status.

type DataSourceStatusProvider

type DataSourceStatusProvider interface {
	// GetStatus returns the current status of the data source.
	//
	// All of the built-in data source implementations are guaranteed to update this status whenever they
	// successfully initialize, encounter an error, or recover after an error.
	GetStatus() DataSourceStatus

	// AddStatusListener subscribes for notifications of status changes. The returned channel will receive a
	// new DataSourceStatus value for any change in status.
	//
	// The listener will be notified whenever any property of the status has changed. See DataSourceStatus for
	// an explanation of the meaning of each property and what could cause it to change.
	//
	// It is the caller's responsibility to consume values from the channel. Allowing values to accumulate in
	// the channel can cause an SDK goroutine to be blocked. If you no longer need the channel, call
	// RemoveStatusListener.
	AddStatusListener() <-chan DataSourceStatus

	// RemoveStatusListener unsubscribes from notifications of status changes. The specified channel must be
	// one that was previously returned by AddStatusListener(); otherwise, the method has no effect.
	RemoveStatusListener(listener <-chan DataSourceStatus)

	// WaitFor is a synchronous method for waiting for a desired connection state.
	//
	// If the current state is already desiredState when this method is called, it immediately returns.
	// Otherwise, it blocks until 1. the state has become desiredState, 2. the state has become
	// DataSourceStateOff (since that is a permanent condition), or 3. the specified timeout elapses.
	//
	// A scenario in which this might be useful is if you want to create the LDClient without waiting
	// for it to initialize, and then wait for initialization at a later time or on a different goroutine:
	//
	//     // create the client but do not wait
	//     client = ld.MakeCustomClient(sdkKey, config, 0)
	//
	//     // later, possibly on another goroutine:
	//     inited := client.GetDataSourceStatusProvider().WaitFor(DataSourceStateValid, 10 * time.Second)
	//     if !inited {
	//         // do whatever is appropriate if initialization has timed out
	//     }
	WaitFor(desiredState DataSourceState, timeout time.Duration) bool
}

DataSourceStatusProvider is an interface for querying the status of a DataSource. The data source is the component that receives updates to feature flag data; normally this is a streaming connection, but it could be polling or file data depending on your configuration.

An implementation of this interface is returned by [github.com/launchdarkly/go-server-sdk/v6.LDClient.GetDataSourceStatusProvider()]. Application code should not implement this interface.

There are three ways to interact with the data source status. One is to simply get the current status; if its State property is DataSourceStateValid, then the SDK is able to receive feature flag updates.

status := client.GetDataSourceStatusProvider().GetStatus()
isValid = status.State == interfaces.DataSourceStateValid

Second, you can use AddStatusListener to get a channel that provides a status update whenever the connection has an error or starts working again.

statusCh := client.GetDataSourceStatusProvider().AddStatusListener()
go func() {
    for newStatus := range statusCh {
        log.Printf("data source status is now: %+v", newStatus)
    }
}()

Third, you can use WaitFor to block until the data source has the desired status. For instance, if you did not want to wait for a connection when you originally created the client, you could set the timeout to zero so that the connection happens in the background. Then, when you need to do something that requires a valid connection (possibly on another goroutine), you can wait until it is valid.

client, _ := ld.MakeCustomClient(sdkKey, config, 0)

// later...
inited := client.GetDataSourceStatusProvider().WaitFor(interfaces.DataSourceStateValid, 10 * time.Second)
if !inited {
    // do whatever is appropriate if initialization has timed out
}

type DataStoreStatus

type DataStoreStatus struct {
	// Available is true if the SDK believes the data store is now available.
	//
	// This property is normally true. If the SDK receives an exception while trying to query or update the
	// data store, then it sets this property to false (notifying listeners, if any) and polls the store at
	// intervals until a query succeeds. Once it succeeds, it sets the property back to true (again
	// notifying listeners).
	Available bool

	// NeedsRefresh is true if the store may be out of date due to a previous outage, so the SDK should
	// attempt to refresh all feature flag data and rewrite it to the store.
	//
	// This property is not meaningful to application code.
	NeedsRefresh bool
}

DataStoreStatus contains information about the status of a data store, provided by DataStoreStatusProvider.

type DataStoreStatusProvider

type DataStoreStatusProvider interface {
	// GetStatus returns the current status of the store.
	//
	// This is only meaningful for persistent stores, or any other DataStore implementation that makes use of
	// the reporting mechanism that is provided by DataStoreUpdateSink. For the default in-memory store, the
	// status will always be reported as "available".
	GetStatus() DataStoreStatus

	// Indicates whether the current data store implementation supports status monitoring.
	//
	// This is normally true for all persistent data stores, and false for the default in-memory store. A true
	// value means that any listeners added with AddStatusListener() can expect to be notified if there is
	// there is any error in storing data, and then notified again when the error condition is resolved. A
	// false value means that the status is not meaningful and listeners should not expect to be notified.
	IsStatusMonitoringEnabled() bool

	// AddStatusListener subscribes for notifications of status changes. The returned channel will receive a
	// new DataStoreStatus value for any change in status.
	//
	// Applications may wish to know if there is an outage in a persistent data store, since that could mean
	// that flag evaluations are unable to get the flag data from the store (unless it is currently cached) and
	// therefore might return default values.
	//
	// If the SDK receives an exception while trying to query or update the data store, then it publishes a
	// DataStoreStatus where Available is false, to indicate that the store appears to be offline, and begins
	// polling the store at intervals until a query succeeds. Once it succeeds, it publishes a new status where
	// Available is true.
	//
	// If the data store implementation does not support status tracking, such as if you are using the default
	// in-memory store rather than a persistent store, it will return a channel that never receives values.
	//
	// It is the caller's responsibility to consume values from the channel. Allowing values to accumulate in
	// the channel can cause an SDK goroutine to be blocked. If you no longer need the channel, call
	// RemoveStatusListener.
	AddStatusListener() <-chan DataStoreStatus

	// RemoveStatusListener unsubscribes from notifications of status changes. The specified channel must be
	// one that was previously returned by AddStatusListener(); otherwise, the method has no effect.
	RemoveStatusListener(<-chan DataStoreStatus)
}

DataStoreStatusProvider is an interface for querying the status of a persistent data store.

An implementation of this interface is returned by github.com/launchdarkly/go-server-sdk/v6.LDClient.GetDataStoreStatusProvider. Application code should not implement this interface.

There are two ways to interact with the data store status. One is to simply get the current status; if its Available property is true, then the store is working normally.

status := client.GetDataStoreStatusProvider().GetStatus()
isValid = status.Available

Second, you can use AddStatusListener to get a channel that provides a status update whenever the data store has an error or starts working again.

statusCh := client.GetDataStoreStatusProvider().AddStatusListener()
go func() {
    for newStatus := range statusCh {
        log.Printf("data store Available is %t", newStatus.Available)
    }
}()

type FlagChangeEvent

type FlagChangeEvent struct {
	// Key is the key of the feature flag whose configuration has changed.
	//
	// The specified flag may have been modified directly, or this may be an indirect change due to a change
	// in some other flag that is a prerequisite for this flag, or a user segment that is referenced in the
	// flag's rules.
	Key string
}

FlagChangeEvent is a parameter type used with FlagTracker.AddFlagChangeListener().

This is not an analytics event to be sent to LaunchDarkly; it is a notification to the application.

type FlagTracker

type FlagTracker interface {
	// AddFlagChangeListener subscribes for notifications of feature flag changes in general.
	//
	// The returned channel will receive a new FlagChangeEvent value whenever the SDK receives any change to
	// any feature flag's configuration, or to a user segment that is referenced by a feature flag. If the
	// updated flag is used as a prerequisite for other flags, the SDK assumes that those flags may now
	// behave differently and sends flag change events for them as well.
	//
	// Note that this does not necessarily mean the flag's value has changed for any particular evaluation
	// context, only that some part of the flag configuration was changed so that it may return a different
	// value than it previously returned for some context. If you want to track flag value changes, use
	// AddFlagValueChangeListener instead.
	//
	// Change events only work if the SDK is actually connecting to LaunchDarkly (or using the file data source).
	// If the SDK is only reading flags from a database (ldcomponents.ExternalUpdatesOnly) then it cannot
	// know when there is a change, because flags are read on an as-needed basis.
	//
	// It is the caller's responsibility to consume values from the channel. Allowing values to accumulate in
	// the channel can cause an SDK goroutine to be blocked.
	AddFlagChangeListener() <-chan FlagChangeEvent

	// RemoveFlagChangeListener unsubscribes from notifications of feature flag changes. The specified channel
	// must be one that was previously returned by AddFlagChangeListener(); otherwise, the method has no effect.
	RemoveFlagChangeListener(listener <-chan FlagChangeEvent)

	// AddFlagValueChangeListener subscribes for notifications of changes in a specific feature flag's value
	// for a specific set of context properties.
	//
	// When you call this method, it first immediately evaluates the feature flag. It then starts listening
	// for feature flag configuration changes (using the same mechanism as AddFlagChangeListener), and whenever
	// the specified feature flag changes, it re-evaluates the flag for the same evaluation context. It then
	// pushes a new FlagValueChangeEvent to the channel if and only if the resulting value has changed.
	//
	// All feature flag evaluations require an instance of ldcontext.Context. If the feature flag you are tracking
	// tracking does not have any targeting rules, you must still pass a dummy context such as
	// ldcontext.New("for-global-flags"). If you do not want the context to appear on your dashboard, use
	// the Anonymous property: ldcontext.NewBuilder("for-global-flags").Anonymous(true).Build().
	//
	// The defaultValue parameter is used if the flag cannot be evaluated; it is the same as the corresponding
	// parameter in LDClient.JSONVariation().
	AddFlagValueChangeListener(
		flagKey string,
		context ldcontext.Context,
		defaultValue ldvalue.Value,
	) <-chan FlagValueChangeEvent

	// RemoveFlagValueChangeListener unsubscribes from notifications of feature flag value changes. The
	// specified channel must be one that was previously returned by AddFlagValueChangeListener(); otherwise,
	// the method has no effect.
	RemoveFlagValueChangeListener(listener <-chan FlagValueChangeEvent)
}

FlagTracker is an interface for tracking changes in feature flag configurations.

An implementation of this interface is returned by github.com/launchdarkly/go-server-sdk/v6.LDClient.GetFlagTracker. Application code should not implement this interface.

type FlagValueChangeEvent

type FlagValueChangeEvent struct {
	// Key is the key of the feature flag whose configuration has changed.
	//
	// The specified flag may have been modified directly, or this may be an indirect change due to a change
	// in some other flag that is a prerequisite for this flag, or a user segment that is referenced in the
	// flag's rules.
	Key string

	// OldValue is the last known value of the flag for the specified evaluation context prior to the update.
	//
	// Since flag values can be of any JSON data type, this is represented as ldvalue.Value. That type has
	// methods for converting to a primitive Java type such as Value.BoolValue().
	//
	// If the flag did not exist before or could not be evaluated, this will be whatever value was
	// specified as the default with AddFlagValueChangeListener().
	OldValue ldvalue.Value

	// NewValue is the new value of the flag for the specified evaluation context.
	//
	// Since flag values can be of any JSON data type, this is represented as ldvalue.Value. That type has
	// methods for converting to a primitive Java type such Value.BoolValue().
	//
	// If the flag could not be evaluated or was deleted, this will be whatever value was specified as
	// the default with AddFlagValueChangeListener().
	NewValue ldvalue.Value
}

FlagValueChangeEvent is a parameter type used with FlagTracker.AddFlagValueChangeListener().

This is not an analytics event to be sent to LaunchDarkly; it is a notification to the application.

type LDClientEvaluations

type LDClientEvaluations interface {
	// BoolVariation returns the value of a boolean feature flag for a given evaluation context.
	//
	// Returns defaultVal if there is an error, if the flag doesn't exist, or the feature is turned off and
	// has no off variation.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#go
	BoolVariation(key string, context ldcontext.Context, defaultVal bool) (bool, error)

	// BoolVariationDetail is the same as [LDClientEvaluation.BoolVariation], but also returns further
	// information about how the value was calculated. The "reason" data will also be included in analytics events.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#go
	BoolVariationDetail(key string, context ldcontext.Context, defaultVal bool) (bool, ldreason.EvaluationDetail, error)

	// IntVariation returns the value of a feature flag (whose variations are integers) for the given evaluation
	// context.
	//
	// Returns defaultVal if there is an error, if the flag doesn't exist, or the feature is turned off and
	// has no off variation.
	//
	// If the flag variation has a numeric value that is not an integer, it is rounded toward zero (truncated).
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#go
	IntVariation(key string, context ldcontext.Context, defaultVal int) (int, error)

	// IntVariationDetail is the same as [LDClientEvaluation.IntVariation], but also returns further information about how
	// the value was calculated. The "reason" data will also be included in analytics events.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#go
	IntVariationDetail(key string, context ldcontext.Context, defaultVal int) (int, ldreason.EvaluationDetail, error)

	// Float64Variation returns the value of a feature flag (whose variations are floats) for the given evaluation
	// context.
	//
	// Returns defaultVal if there is an error, if the flag doesn't exist, or the feature is turned off and
	// has no off variation.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#go
	Float64Variation(key string, context ldcontext.Context, defaultVal float64) (float64, error)

	// Float64VariationDetail is the same as [LDClientEvaluation.Float64Variation], but also returns further
	// information about how the value was calculated. The "reason" data will also be included in analytics events.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#go
	Float64VariationDetail(
		key string,
		context ldcontext.Context,
		defaultVal float64,
	) (float64, ldreason.EvaluationDetail, error)

	// StringVariation returns the value of a feature flag (whose variations are strings) for the given evaluation
	// context.
	//
	// Returns defaultVal if there is an error, if the flag doesn't exist, or the feature is turned off and has
	// no off variation.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#go
	StringVariation(key string, context ldcontext.Context, defaultVal string) (string, error)

	// StringVariationDetail is the same as [LDClientEvaluation.StringVariation], but also returns further
	// information about how the value was calculated. The "reason" data will also be included in analytics events.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#go
	StringVariationDetail(
		key string,
		context ldcontext.Context,
		defaultVal string,
	) (string, ldreason.EvaluationDetail, error)

	// JSONVariation returns the value of a feature flag for the given evaluation context, allowing the value to
	// be of any JSON type.
	//
	// The value is returned as an ldvalue.Value, which can be inspected or converted to other types using
	// Value methods such as GetType() and BoolValue(). The defaultVal parameter also uses this type. For
	// instance, if the values for this flag are JSON arrays:
	//
	//     defaultValAsArray := ldvalue.BuildArray().
	//         Add(ldvalue.String("defaultFirstItem")).
	//         Add(ldvalue.String("defaultSecondItem")).
	//         Build()
	//     result, err := client.JSONVariation(flagKey, context, defaultValAsArray)
	//     firstItemAsString := result.GetByIndex(0).StringValue() // "defaultFirstItem", etc.
	//
	// You can also use unparsed json.RawMessage values:
	//
	//     defaultValAsRawJSON := ldvalue.Raw(json.RawMessage(`{"things":[1,2,3]}`))
	//     result, err := client.JSONVariation(flagKey, context, defaultValAsJSON
	//     resultAsRawJSON := result.AsRaw()
	//
	// Returns defaultVal if there is an error, if the flag doesn't exist, or the feature is turned off.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#go
	JSONVariation(key string, context ldcontext.Context, defaultVal ldvalue.Value) (ldvalue.Value, error)

	// JSONVariationDetail is the same as [LDClientEvaluation.JSONVariation], but also returns further
	// information about how the value was calculated. The "reason" data will also be included in analytics events.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#go
	JSONVariationDetail(key string, context ldcontext.Context, defaultVal ldvalue.Value) (
		ldvalue.Value, ldreason.EvaluationDetail, error)

	// AllFlagsState returns an object that encapsulates the state of all feature flags for a given evaluation
	// context.
	// This includes the flag values, and also metadata that can be used on the front end.
	//
	// The most common use case for this method is to bootstrap a set of client-side feature flags from a
	// back-end service.
	//
	// You may pass any combination of flagstate.ClientSideOnly, flagstate.WithReasons, and
	// flagstate.DetailsOnlyForTrackedFlags as optional parameters to control what data is included.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/all-flags#go
	AllFlagsState(context ldcontext.Context, options ...flagstate.Option) flagstate.AllFlags
}

LDClientEvaluations defines the basic feature flag evaluation methods implemented by LDClient.

type LDClientEvents

type LDClientEvents interface {
	// Identify reports details about an evaluation context.
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/identify#go
	Identify(context ldcontext.Context) error

	// TrackEvent reports an event associated with an evaluation context.
	//
	// The eventName parameter is defined by the application and will be shown in analytics reports;
	// it normally corresponds to the event name of a metric that you have created through the
	// LaunchDarkly dashboard. If you want to associate additional data with this event, use\
	// [LDClientEvents.TrackData] or [LDClientEvents.TrackMetric].
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/events#go
	TrackEvent(eventName string, context ldcontext.Context) error

	// TrackData reports an event associated with an evaluation context, and adds custom data.
	//
	// The eventName parameter is defined by the application and will be shown in analytics reports;
	// it normally corresponds to the event name of a metric that you have created through the
	// LaunchDarkly dashboard.
	//
	// The data parameter is a value of any JSON type, represented with the ldvalue.Value type, that
	// will be sent with the event. If no such value is needed, use [ldvalue.Null]() (or call
	// [LDClientEvents.TrackEvent] instead). To send a numeric value for experimentation, use
	// [LDClientEvents.TrackMetric].
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/events#go
	TrackData(eventName string, context ldcontext.Context, data ldvalue.Value) error

	// TrackMetric reports an event associated with an evaluation context, and adds a numeric value.
	// This value is used by the LaunchDarkly experimentation feature in numeric custom metrics, and will also
	// be returned as part of the custom event for Data Export.
	//
	// The eventName parameter is defined by the application and will be shown in analytics reports;
	// it normally corresponds to the event name of a metric that you have created through the
	// LaunchDarkly dashboard.
	//
	// The data parameter is a value of any JSON type, represented with the [ldvalue.Value] type, that
	// will be sent with the event. If no such value is needed, use [ldvalue.Null]().
	//
	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/events#go
	TrackMetric(eventName string, context ldcontext.Context, metricValue float64, data ldvalue.Value) error
}

LDClientEvents defines the methods implemented by LDClient that are specifically for generating analytics events. Events may also be generated as a side effect of the methods in LDClientEvaluations.

type LDClientInterface

type LDClientInterface interface {
	LDClientEvaluations
	LDClientEvents

	// WithEventsDisabled returns a decorator for the client that implements the same basic operations
	// but will not generate any analytics events.
	//
	// If events were already disabled, this is just the same object. Otherwise, it is an object whose
	// Variation methods use the same LDClient to evaluate feature flags, but without generating any
	// events, and whose Identify/Track/Custom methods do nothing. Neither evaluation counts nor context
	// properties will be sent to LaunchDarkly for any operations done with this object.
	//
	// You can use this to suppress events within some particular area of your code where you do not want
	// evaluations to affect your dashboard statistics, or do not want to incur the overhead of processing
	// the events.
	//
	// Note that if the original client configuration already had events disabled
	// (config.Events = ldcomponents.NoEvents()), you cannot re-enable them with this method. It is only
	// useful for temporarily disabling events on a client that had them enabled, or re-enabling them on
	// an LDClientInterface that was the result of WithEventsDisabled(true).
	//
	//     // Assuming you did not disable events when creating the client,
	//     // this evaluation generates an event:
	//     value, err := client.BoolVariation("flagkey1", context, false)
	//
	//     // Now we want to do some evaluations without events
	//     tempClient := client.WithEventsDisabled(true)
	//     value, err = tempClient.BoolVariation("flagkey2", context, false)
	//     value, err = tempClient.BoolVariation("flagkey3", context, false)
	WithEventsDisabled(eventsDisabled bool) LDClientInterface
}

LDClientInterface defines the basic SDK client operations implemented by LDClient.

This includes all methods for evaluating a feature flag or generating analytics events, as defined by LDEvaluations and LDEvents. It does not include general control operations like Flush(), Close(), or GetDataSourceStatusProvider().

type ServiceEndpoints

type ServiceEndpoints struct {
	Streaming string
	Polling   string
	Events    string
}

ServiceEndpoints allow configuration of custom service URIs.

If you want to set non-default values for any of these fields, set the ServiceEndpoints field in the SDK's github.com/launchdarkly/go-server-sdk/v6.Config struct. You may set individual values such as Streaming, or use the helper method github.com/launchdarkly/go-server-sdk/v6/ldcomponents.RelayProxyEndpoints.

See Config.ServiceEndpoints for more details.

Directories

Path Synopsis
Package flagstate contains the data types used by the LDClient.AllFlagsState() method.
Package flagstate contains the data types used by the LDClient.AllFlagsState() method.

Jump to

Keyboard shortcuts

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