flagstate

package
v6.0.0-alpha.pub.13 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package flagstate contains the data types used by the LDClient.AllFlagsState() method. These types are used when obtaining a snapshot of a set of feature flags at once.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllFlags

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

AllFlags is a snapshot of the state of multiple feature flags with regard to a specific evaluation context. This is the return type of LDClient.AllFlagsState().

Serializing this object to JSON using json.Marshal() will produce the appropriate data structure for bootstrapping the LaunchDarkly JavaScript client.

func (AllFlags) GetFlag

func (a AllFlags) GetFlag(flagKey string) (FlagState, bool)

GetFlag looks up information for a specific flag by key. The returned FlagState struct contains the flag flag evaluation result and flag metadata that was recorded when LDClient.AllFlagsState() was called. The second return value is true if successful, or false if there was no such flag.

func (AllFlags) GetValue

func (a AllFlags) GetValue(flagKey string) ldvalue.Value

GetValue returns the value of an individual feature flag at the time the state was recorded. The return value will be ldvalue.Null() if the flag returned the default value, or if there was no such flag.

This is equivalent to calling GetFlag for the flag and then getting the Value property.

func (AllFlags) IsValid

func (a AllFlags) IsValid() bool

IsValid returns true if the call to LDClient.AllFlagsState() succeeded. It returns false if there was an error (such as the data store not being available), in which case no flag data is in this object.

func (AllFlags) MarshalJSON

func (a AllFlags) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom JSON serialization for AllFlags, to produce the correct data structure for "bootstrapping" the LaunchDarkly JavaScript client.

func (AllFlags) ToValuesMap

func (a AllFlags) ToValuesMap() map[string]ldvalue.Value

ToValuesMap returns a map of flag keys to flag values. If a flag would have evaluated to the default value, its value will be ldvalue.Null().

Do not use this method if you are passing data to the front end to "bootstrap" the JavaScript client. Instead, convert the state object to JSON using json.Marshal.

type AllFlagsBuilder

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

AllFlagsBuilder is a builder that creates AllFlags instances. This is normally done only by the SDK, but it may also be used in test code.

AllFlagsBuilder methods should not be used concurrently from multiple goroutines.

func NewAllFlagsBuilder

func NewAllFlagsBuilder(options ...Option) *AllFlagsBuilder

NewAllFlagsBuilder creates a builder for constructing an AllFlags instance. This is normally done only by the SDK, but it may also be used in test code.

func (*AllFlagsBuilder) AddFlag

func (b *AllFlagsBuilder) AddFlag(flagKey string, flag FlagState) *AllFlagsBuilder

AddFlag adds information about a flag.

The Reason property in the FlagState may or may not be recorded in the State, depending on the builder options.

func (*AllFlagsBuilder) Build

func (b *AllFlagsBuilder) Build() AllFlags

Build returns an immutable State instance copied from the current builder data.

type FlagState

type FlagState struct {
	// Value is the result of evaluating the flag for the specified evaluation context.
	Value ldvalue.Value

	// Variation is the variation index that was selected for the specified evaluation context.
	Variation ldvalue.OptionalInt

	// Version is the flag's version number when it was evaluated. This is an int rather than an OptionalInt
	// because a flag always has a version and nonexistent flag keys are not included in AllFlags.
	Version int

	// Reason is the evaluation reason from evaluating the flag.
	Reason ldreason.EvaluationReason

	// TrackEvents is true if a full feature event must be sent whenever evaluating this flag. This will be
	// true if tracking was explicitly enabled for this flag for data export, or if the evaluation involved
	// an experiment, or both.
	TrackEvents bool

	// TrackReason is true if the evaluation reason should always be included in any full feature event
	// created for this flag, regardless of whether variationDetail was called. This will be true if the
	// evaluation involved an experiment.
	TrackReason bool

	// DebugEventsUntilDate is non-zero if event debugging is enabled for this flag until the specified time.
	DebugEventsUntilDate ldtime.UnixMillisecondTime

	// OmitDetails is true if, based on the options passed to AllFlagsState and the flag state, some of the
	// metadata can be left out of the JSON representation.
	OmitDetails bool
}

FlagState represents the state of an individual feature flag, with regard to a specific evaluation context, at the time when LDClient.AllFlagsState() was called.

type Option

type Option interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

Option is the interface for optional parameters that can be passed to LDClient.AllFlagsState.

func OptionClientSideOnly

func OptionClientSideOnly() Option

OptionClientSideOnly is an option that can be passed to LDClient.AllFlagsState().

It specifies that only flags marked for use with the client-side SDK should be included in the state object. By default, all flags are included.

func OptionDetailsOnlyForTrackedFlags

func OptionDetailsOnlyForTrackedFlags() Option

OptionDetailsOnlyForTrackedFlags is an option that can be passed to LDClient.AllFlagsState(). It specifies that any flag metadata that is normally only used for event generation - such as flag versions and evaluation reasons - should be omitted for any flag that does not have event tracking or debugging turned on. This reduces the size of the JSON data if you are passing the flag state to the front end.

func OptionWithReasons

func OptionWithReasons() Option

OptionWithReasons is an option that can be passed to LDClient.AllFlagsState(). It specifies that evaluation reasons should be included in the state object. By default, they are not.

Jump to

Keyboard shortcuts

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