ldmodel

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: Apache-2.0 Imports: 11 Imported by: 6

Documentation

Overview

Package ldmodel contains the LaunchDarkly Go SDK feature flag data model.

These types contain the subset of feature flag and user segment data that is sent by LaunchDarkly to the SDK.

There is a defined JSON schema for these types that is used in communication between the SDK and LaunchDarkly services, which is also the JSON encoding used for storing flags/segments in a persistent data store. The JSON schema does not correspond exactly to the exported field structure of these types; the ldmodel package provides functions for explicitly converting the types to and from JSON. See DataModelSerialization for details.

Normal use of the Go SDK does not require referencing this package directly. It is used internally by the SDK, but is published and versioned separately so it can be used in other LaunchDarkly components without making the SDK versioning dependent on these internal APIs.

The bulk of the flag evaluation logic is in the main go-server-sdk-evaluation package, rather than in these data model types. However, in order to allow certain optimizations that could not be done from outside the package without exposing implementation details in the API, some of the logic (such as target and clause matching) is implemented here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClauseMatchesUser

func ClauseMatchesUser(c *Clause, user *lduser.User) bool

ClauseMatchesUser return true if the user matches the conditions in this clause.

This method cannot be used if the clause's Operation is OperatorSegmentMatch, since that involves pulling data from outside of the clause. In that case it will simply return false.

This part of the flag evaluation logic is defined in ldmodel and exported, rather than being internal to Evaluator, as a compromise to allow for optimizations that require storing precomputed data in the model object. Exporting this function is preferable to exporting those internal implementation details.

The clause and user are passed by reference for efficiency only; the function will not modify them. Passing a nil value will cause a panic.

func MarshalFeatureFlagToJSONWriter added in v1.1.0

func MarshalFeatureFlagToJSONWriter(item FeatureFlag, writer *jwriter.Writer)

MarshalFeatureFlagToJSONWriter attempts to convert a FeatureFlag to JSON using the jsonstream API. For details, see: https://gopkg.in/launchdarkly/go-jsonstream.v1

func MarshalSegmentToJSONWriter added in v1.1.0

func MarshalSegmentToJSONWriter(item Segment, writer *jwriter.Writer)

MarshalSegmentToJSONWriter attempts to convert a Segment to JSON using the jsonstream API. For details, see: https://gopkg.in/launchdarkly/go-jsonstream.v1

func PreprocessFlag

func PreprocessFlag(f *FeatureFlag)

PreprocessFlag precomputes internal data structures based on the flag configuration, to speed up evaluations.

This is called once after a flag is deserialized from JSON, or is created with ldbuilders. If you construct a flag by some other means, you should call PreprocessFlag exactly once before making it available to any other code. The method is not safe for concurrent access across goroutines.

func PreprocessSegment

func PreprocessSegment(s *Segment)

PreprocessSegment precomputes internal data structures based on the segment configuration, to speed up evaluations.

This is called once after a segment is deserialized from JSON, or is created with ldbuilders. If you construct a segment by some other means, you should call PreprocessSegment exactly once before making it available to any other code. The method is not safe for concurrent access across goroutines.

func SegmentIncludesOrExcludesKey

func SegmentIncludesOrExcludesKey(s *Segment, userKey string) (included bool, found bool)

SegmentIncludesOrExcludesKey tests whether the specified user key is in the include or exclude list of this Segment. If it is in either, then the first return value is true for include or false for exclude, and the second return value is true. If it is in neither, both return values are false.

This is only valid for regular segments that contain their entire target lists. Big segments, which reference an external data store, are handled differently by Evaluator.

This part of the flag evaluation logic is defined in ldmodel and exported, rather than being internal to Evaluator, as a compromise to allow for optimizations that require storing precomputed data in the model object. Exporting this function is preferable to exporting those internal implementation details.

The segment passed by reference for efficiency only; the function will not modify it. Passing a nil value will cause a panic.

func TargetContainsKey

func TargetContainsKey(t *Target, key string) bool

TargetContainsKey returns true if the specified user key is in this Target.

This part of the flag evaluation logic is defined in ldmodel and exported, rather than being internal to Evaluator, as a compromise to allow for optimizations that require storing precomputed data in the model object. Exporting this function is preferable to exporting those internal implementation details.

The target passed by reference for efficiency only; the function will not modify it. Passing a nil value will cause a panic.

Types

type Clause

type Clause struct {
	// Attribute specifies the user attribute that is being tested.
	//
	// This is required for all Operator types except SegmentMatch.
	//
	// If the user's value for this attribute is a JSON array, then the test specified in the Clause is
	// repeated for each value in the array until a match is found or there are no more values.
	Attribute lduser.UserAttribute
	// Op specifies the type of test to perform.
	Op Operator
	// Values is a list of values to be compared to the user attribute.
	//
	// This is interpreted as an OR: if the user attribute matches any of these values with the specified
	// operator, the Clause matches the user.
	//
	// In the special case where Op is OperatorSegmentMtach, there should only be a single Value, which
	// must be a string: the key of the user segment.
	//
	// If the user does not have a value for the specified attribute, the Values are ignored and the
	// Clause is always treated as a non-match.
	Values []ldvalue.Value
	// Negate is true if the specified Operator should be inverted.
	//
	// For instance, this would cause OperatorIn to mean "not equal" rather than "equal". Note that if no
	// tests are performed for this Clause because the user does not have a value for the specified
	// attribute, then Negate will not come into effect (the Clause will just be treated as a non-match).
	Negate bool
	// contains filtered or unexported fields
}

Clause describes an individual clause within a FlagRule or SegmentRule.

type ClientSideAvailability

type ClientSideAvailability struct {
	// UsingMobileKey indicates that this flag is available to clients using the mobile key for authorization
	// (includes most desktop and mobile clients).
	UsingMobileKey bool
	// UsingEnvironmentID indicates that this flag is available to clients using the environment id to identify an
	// environment (includes client-side javascript clients).
	UsingEnvironmentID bool
	// Explicit is true if, when serializing this flag, all of the ClientSideAvailability properties should
	// be included. If it is false, then an older schema is used in which this object is entirely omitted,
	// UsingEnvironmentID is stored in a deprecated property, and UsingMobileKey is assumed to be true.
	//
	// This field exists to ensure that flag representations remain consistent when sent and received
	// even though the clientSideAvailability property may not be present in the JSON data. It is false
	// if the flag was deserialized from an older JSON schema that did not include that property.
	//
	// Similarly, when deserializing a flag, if it used the older schema then Explicit will be false and
	// UsingMobileKey will be true.
	Explicit bool
}

ClientSideAvailability describes whether a flag is available to client-side SDKs.

This field can be used by a server-side client to determine whether to include an individual flag in bootstrapped set of flag data (see https://docs.launchdarkly.com/sdk/client-side/javascript#bootstrapping).

type DataModelSerialization

type DataModelSerialization interface {
	// MarshalFeatureFlag converts a FeatureFlag into its serialized encoding.
	MarshalFeatureFlag(item FeatureFlag) ([]byte, error)

	// MarshalSegment converts a Segment into its serialized encoding.
	MarshalSegment(item Segment) ([]byte, error)

	// UnmarshalFeatureFlag attempts to convert a FeatureFlag from its serialized encoding.
	UnmarshalFeatureFlag(data []byte) (FeatureFlag, error)

	// UnmarshalFeatureFlag attempts to convert a FeatureFlag from its serialized encoding.
	UnmarshalSegment(data []byte) (Segment, error)
}

DataModelSerialization is an abstraction of an encoding for SDK data model objects.

The ldmodel package defines a standard JSON schema for FeatureFlag and Segment. Currently, this is the only encoding that is used, so the only implementation of DataModelSerialization is the one provided by NewDataModelSerialization(), but the interface allows for the possibility that other encodings will be defined in the future.

There are also other ways to convert these types to and from the JSON encoding:

1. FeatureFlag and Segment define MarshalJSON and UnmarshalJSON methods so that they wil be correctly encoded or decoded if you call Go's standard json.Marshal or json.Unmarshal.

2. There are equivalent methods for encoding and decoding via the go-jsonstream API (https://pkg.go.dev/gopkg.in/launchdarkly/go-jsonstream.v1). These are used internally by the SDK to avoid inefficiencies in json.Marshal and json.Unmarshal.

3. If the build tag "launchdarkly_easyjson" is set, FeatureFlag and Segment will also define MarshalEasyJSON and UnmarshalEasyJSON methods for interoperability with the easyjson library. For details, see the go-jsonstream documentation.

There is no separately defined encoding for lower-level data model types such as FlagRule, since there is no guarantee that those will always be represented as individual JSON objects in future versions of the schema. If you want to create a JSON representation of those data structures you must define your own type and copy values into it.

func NewJSONDataModelSerialization

func NewJSONDataModelSerialization() DataModelSerialization

NewJSONDataModelSerialization provides the default JSON encoding for SDK data model objects.

Always use this rather than relying on json.Marshal() and json.Unmarshal(). The data model structs are guaranteed to serialize and deserialize correctly with json.Marshal() and json.Unmarshal(), but JSONDataModelSerialization may be enhanced in the future to use a more efficient mechanism.

type FeatureFlag

type FeatureFlag struct {
	// Key is the unique string key of the feature flag.
	Key string
	// On is true if targeting is turned on for this flag.
	//
	// If On is false, the evaluator always uses OffVariation and ignores all other fields.
	On bool
	// Prerequisites is a list of feature flag conditions that are prerequisites for this flag.
	//
	// If any prerequisite is not met, the flag behaves as if targeting is turned off.
	Prerequisites []Prerequisite
	// Targets contains sets of individually targeted users.
	//
	// Targets take precedence over Rules: if a user is matched by any Target, the Rules are ignored.
	// Targets are ignored if targeting is turned off.
	Targets []Target
	// Rules is a list of rules that may match a user.
	//
	// If a user is matched by a Rule, all subsequent Rules in the list are skipped. Rules are ignored
	// if targeting is turned off.
	Rules []FlagRule
	// Fallthrough defines the flag's behavior if targeting is turned on but the user is not matched
	// by any Target or Rule.
	Fallthrough VariationOrRollout
	// OffVariation specifies the variation index to use if targeting is turned off.
	//
	// If this is undefined (ldvalue.OptionalInt{}), Evaluate returns undefined for the variation
	// index and ldvalue.Null() for the value.
	OffVariation ldvalue.OptionalInt
	// Variations is the list of all allowable variations for this flag. The variation index in a
	// Target or Rule is a zero-based index to this list.
	Variations []ldvalue.Value
	// ClientSideAvailability indicates whether a flag is available using each of the client-side
	// authentication methods.
	ClientSideAvailability ClientSideAvailability
	// Salt is a randomized value assigned to this flag when it is created.
	//
	// The hash function used for calculating percentage rollouts uses this as a salt to ensure that
	// rollouts are consistent within each flag but not predictable from one flag to another.
	Salt string
	// TrackEvents is used internally by the SDK analytics event system.
	//
	// This field is true if the current LaunchDarkly account has data export enabled, and has turned on
	// the "send detailed event information for this flag" option for this flag. This tells the SDK to
	// send full event data for each flag evaluation, rather than only aggregate data in a summary event.
	//
	// The go-server-sdk-evaluation package does not implement that behavior; it is only in the data
	// model for use by the SDK.
	TrackEvents bool
	// TrackEventsFallthrough is used internally by the SDK analytics event system.
	//
	// This field is true if the current LaunchDarkly account has experimentation enabled, has associated
	// this flag with an experiment, and has enabled "default rule" for the experiment. This tells the
	// SDK to send full event data for any evaluation where this flag had targeting turned on but the
	// user did not match any targets or rules.
	//
	// The go-server-sdk-evaluation package does not implement that behavior; it is only in the data
	// model for use by the SDK.
	TrackEventsFallthrough bool
	// DebugEventsUntilDate is used internally by the SDK analytics event system.
	//
	// This field is non-zero if debugging for this flag has been turned on temporarily in the
	// LaunchDarkly dashboard. Debugging always is for a limited time, so the field specifies a Unix
	// millisecond timestamp when this mode should expire. Until then, the SDK will send full event data
	// for each evaluation of this flag.
	//
	// The go-server-sdk-evaluation package does not implement that behavior; it is only in the data
	// model for use by the SDK.
	DebugEventsUntilDate ldtime.UnixMillisecondTime
	// Version is an integer that is incremented by LaunchDarkly every time the configuration of the flag is
	// changed.
	Version int
	// Deleted is true if this is not actually a feature flag but rather a placeholder (tombstone) for a
	// deleted flag. This is only relevant in data store implementations. The SDK does not evaluate
	// deleted flags.
	Deleted bool
}

FeatureFlag describes an individual feature flag.

The fields of this struct are exported for use by LaunchDarkly internal components. Application code should normally not reference FeatureFlag fields directly; flag data normally comes from LaunchDarkly SDK endpoints in JSON form and can be deserialized using the DataModelSerialization interface.

func UnmarshalFeatureFlagFromJSONReader added in v1.1.0

func UnmarshalFeatureFlagFromJSONReader(reader *jreader.Reader) FeatureFlag

UnmarshalFeatureFlagFromJSONReader attempts to convert a FeatureFlag from JSON using the jsonstream API. For details, see: https://gopkg.in/launchdarkly/go-jsonstream.v1

func (*FeatureFlag) GetDebugEventsUntilDate

func (f *FeatureFlag) GetDebugEventsUntilDate() ldtime.UnixMillisecondTime

GetDebugEventsUntilDate returns zero normally, but if event debugging has been temporarily enabled for the flag, it returns the time at which debugging mode should expire.

This method exists in order to conform to interfaces used internally by the SDK (go-sdk-events.v1/FlagEventProperties). It simply returns DebugEventsUntilDate.

func (*FeatureFlag) GetKey

func (f *FeatureFlag) GetKey() string

GetKey returns the string key for the flag.

This method exists in order to conform to interfaces used internally by the SDK.

func (*FeatureFlag) GetVersion

func (f *FeatureFlag) GetVersion() int

GetVersion returns the version of the flag.

This method exists in order to conform to interfaces used internally by the SDK.

func (*FeatureFlag) IsExperimentationEnabled

func (f *FeatureFlag) IsExperimentationEnabled(reason ldreason.EvaluationReason) bool

IsExperimentationEnabled returns true if, based on the EvaluationReason returned by the flag evaluation, an event for that evaluation should have full tracking enabled and always report the reason even if the application didn't explicitly request this. For instance, this is true if a rule was matched that had tracking enabled for that specific rule.

This differs from IsFullEventTrackingEnabled() in that it is dependent on the result of a specific evaluation; also, IsFullEventTrackingEnabled() being true does not imply that the event should always contain a reason, whereas IsExperimentationEnabled() being true does force the reason to be included.

This method exists in order to conform to interfaces used internally by the SDK (go-sdk-events.v1/FlagEventProperties).

func (*FeatureFlag) IsFullEventTrackingEnabled

func (f *FeatureFlag) IsFullEventTrackingEnabled() bool

IsFullEventTrackingEnabled returns true if the flag has been configured to always generate detailed event data.

This method exists in order to conform to interfaces used internally by the SDK (go-sdk-events.v1/FlagEventProperties). It simply returns TrackEvents.

func (FeatureFlag) MarshalJSON

func (f FeatureFlag) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default json.Marshal behavior to provide the same marshalling behavior that is used by NewJSONDataModelSerialization().

func (*FeatureFlag) UnmarshalJSON

func (f *FeatureFlag) UnmarshalJSON(data []byte) error

UnmarshalJSON overrides the default json.Unmarshal behavior to provide the same unmarshalling behavior that is used by NewJSONDataModelSerialization().

type FlagRule

type FlagRule struct {
	// VariationRollout properties for a FlagRule define what variation to return if the user matches
	// this rule.
	VariationOrRollout
	// ID is a randomized identifier assigned to each rule when it is created.
	//
	// This is used to populate the RuleID property of ldreason.EvaluationReason.
	ID string
	// Clauses is a list of test conditions that make up the rule. These are ANDed: every Clause must
	// match in order for the FlagRule to match.
	Clauses []Clause
	// TrackEvents is used internally by the SDK analytics event system.
	//
	// This field is true if the current LaunchDarkly account has experimentation enabled, has associated
	// this flag with an experiment, and has enabled this rule for the experiment. This tells the SDK to
	// send full event data for any evaluation that matches this rule.
	//
	// The go-server-sdk-evaluation package does not implement that behavior; it is only in the data
	// model for use by the SDK.
	TrackEvents bool
}

FlagRule describes a single rule within a feature flag.

A rule consists of a set of ANDed matching conditions (Clause) for a user, along with either a fixed variation or a set of rollout percentages to use if the user matches all of the clauses.

type Operator

type Operator string

Operator describes an operator for a clause.

const (
	// OperatorIn matches a user value and clause value if the two values are equal (including their type).
	OperatorIn Operator = "in"
	// OperatorEndsWith matches a user value and clause value if they are both strings and the former ends with
	// the latter.
	OperatorEndsWith Operator = "endsWith"
	// OperatorStartsWith matches a user value and clause value if they are both strings and the former starts
	// with the latter.
	OperatorStartsWith Operator = "startsWith"
	// OperatorMatches matches a user value and clause value if they are both strings and the latter is a valid
	// regular expression that matches the former.
	OperatorMatches Operator = "matches"
	// OperatorContains matches a user value and clause value if they are both strings and the former contains
	// the latter.
	OperatorContains Operator = "contains"
	// OperatorLessThan matches a user value and clause value if they are both numbers and the former < the
	// latter.
	OperatorLessThan Operator = "lessThan"
	// OperatorLessThanOrEqual matches a user value and clause value if they are both numbers and the former
	// <= the latter.
	OperatorLessThanOrEqual Operator = "lessThanOrEqual"
	// OperatorGreaterThan matches a user value and clause value if they are both numbers and the former > the
	// latter.
	OperatorGreaterThan Operator = "greaterThan"
	// OperatorGreaterThanOrEqual matches a user value and clause value if they are both numbers and the former
	// >= the latter.
	OperatorGreaterThanOrEqual Operator = "greaterThanOrEqual"
	// OperatorBefore matches a user value and clause value if they are both timestamps and the former < the
	// latter.
	//
	// A valid timestamp is either a string in RFC3339/ISO8601 format, or a number which is treated as Unix
	// milliseconds.
	OperatorBefore Operator = "before"
	// OperatorAfter matches a user value and clause value if they are both timestamps and the former > the
	// latter.
	//
	// A valid timestamp is either a string in RFC3339/ISO8601 format, or a number which is treated as Unix
	// milliseconds.
	OperatorAfter Operator = "after"
	// OperatorSegmentMatch matches a user if the user is included in the user segment whose key is the clause
	// value.
	OperatorSegmentMatch Operator = "segmentMatch"
	// OperatorSemVerEqual matches a user value and clause value if they are both semantic versions and they
	// are equal.
	//
	// A semantic version is a string that either follows the Semantic Versions 2.0 spec, or is an abbreviated
	// version consisting of digits and optional periods in the form "m" (equivalent to m.0.0) or "m.n"
	// (equivalent to m.n.0).
	OperatorSemVerEqual Operator = "semVerEqual"
	// OperatorSemVerLessThan matches a user value and clause value if they are both semantic versions and the
	// former < the latter.
	//
	// A semantic version is a string that either follows the Semantic Versions 2.0 spec, or is an abbreviated
	// version consisting of digits and optional periods in the form "m" (equivalent to m.0.0) or "m.n"
	// (equivalent to m.n.0).
	OperatorSemVerLessThan Operator = "semVerLessThan"
	// OperatorSemVerGreaterThan matches a user value and clause value if they are both semantic versions and
	// the former > the latter.
	//
	// A semantic version is a string that either follows the Semantic Versions 2.0 spec, or is an abbreviated
	// version consisting of digits and optional periods in the form "m" (equivalent to m.0.0) or "m.n"
	// (equivalent to m.n.0).
	OperatorSemVerGreaterThan Operator = "semVerGreaterThan"
)

List of available operators

type Prerequisite

type Prerequisite struct {
	// Key is the unique key of the feature flag to be evaluated as a prerequisite.
	Key string
	// Variation is the index of the variation that the prerequisite flag must return in order for
	// the prerequisite condition to be met. If the prerequisite flag has targeting turned on, then
	// the condition is not met even if the flag's OffVariation matches this value. This is always a
	// real variation index; it cannot be undefined.
	Variation int
}

Prerequisite describes a requirement that another feature flag return a specific variation.

A prerequisite condition is met if the specified prerequisite flag has targeting turned on and returns the specified variation.

type Rollout

type Rollout struct {
	// Kind specifies whether this rollout is a simple percentage rollout or represents an experiment. Experiments have
	// different behaviour for tracking and variation bucketing.
	Kind RolloutKind
	// Variations is a list of the variations in the percentage rollout and what percentage of users
	// to include in each.
	//
	// The Weight values of all elements in this list should add up to 100000 (100%). If they do not,
	// the last element in the list will behave as if it includes any leftover percentage (that is, if
	// the weights are [1000, 1000, 1000] they will be treated as if they were [1000, 1000, 98000]).
	Variations []WeightedVariation
	// BucketBy specifies which user attribute should be used to distinguish between users in a rollout.
	//
	// The default (when BucketBy is empty) is lduser.KeyAttribute, the user's primary key. If you wish to
	// treat users with different keys as the same for rollout purposes as long as they have the same
	// "country" attribute, you would set this to "country" (lduser.CountryAttribute).
	//
	// Rollouts always take the user's "secondary key" attribute into account as well if the user has one.
	BucketBy lduser.UserAttribute
	// Seed, if present, specifies the seed for the hashing algorithm this rollout will use to bucket users, so that
	// rollouts with the same Seed will assign the same users to the same buckets.
	// If unspecified, the seed will default to a combination of the flag key and flag-level Salt.
	Seed ldvalue.OptionalInt
}

Rollout describes how users will be bucketed into variations during a percentage rollout.

func (Rollout) IsExperiment added in v1.3.0

func (r Rollout) IsExperiment() bool

IsExperiment returns whether this rollout represents an experiment.

type RolloutKind added in v1.3.0

type RolloutKind string

RolloutKind describes whether a rollout is a simple percentage rollout or represents an experiment. Experiments have different behaviour for tracking and variation bucketing.

const (
	// RolloutKindRollout represents a simple percentage rollout. This is the default rollout kind, and will be assumed if
	// not otherwise specified.
	RolloutKindRollout RolloutKind = "rollout"
	// RolloutKindExperiment represents an experiment. Experiments have different behaviour for tracking and variation
	// bucketing.
	RolloutKindExperiment RolloutKind = "experiment"
)

type Segment

type Segment struct {
	// Key is the unique key of the user segment.
	Key string
	// Included is a list of user keys that are always matched by this segment.
	Included []string
	// Excluded is a list of user keys that are never matched by this segment, unless the key is also in Included.
	Excluded []string
	// Salt is a randomized value assigned to this user segment when it is created.
	//
	// The hash function used for calculating percentage rollouts uses this as a salt to ensure that
	// rollouts are consistent within each segment but not predictable from one segment to another.
	Salt string
	// Rules is a list of rules that may match a user.
	//
	// If a user is matched by a Rule, all subsequent Rules in the list are skipped. Rules are ignored
	// if the user's key is in Included or Excluded.
	Rules []SegmentRule
	// Unbounded is true if this is a segment whose Included list is stored separately and is not limited in size.
	// Currently, the server-side Go SDK cannot access the user list for this kind of segment; it only works when
	// flags are being evaluated within the LaunchDarkly service.
	//
	// The name is historical: "unbounded segments" was an earlier name for the product feature that is currently
	// known as "big segments". If Unbounded is true, this is a big segment.
	Unbounded bool
	// Version is an integer that is incremented by LaunchDarkly every time the configuration of the segment is
	// changed.
	Version int
	// Generation is an integer that indicates which set of big segment data is currently active for this segment
	// key. LaunchDarkly increments it if a segment is deleted and recreated. This value is only meaningful for big
	// segments. If this field is unset, it means the segment representation used an older schema so the generation
	// is unknown, in which case matching a big segment is not possible.
	Generation ldvalue.OptionalInt
	// Deleted is true if this is not actually a user segment but rather a placeholder (tombstone) for a
	// deleted segment. This is only relevant in data store implementations.
	Deleted bool
	// contains filtered or unexported fields
}

Segment describes a group of users based on user keys and/or matching rules.

func UnmarshalSegmentFromJSONReader added in v1.1.0

func UnmarshalSegmentFromJSONReader(reader *jreader.Reader) Segment

UnmarshalSegmentFromJSONReader attempts to convert a Segment from JSON using the jsonstream API. For details, see: https://gopkg.in/launchdarkly/go-jsonstream.v1

func (*Segment) GetKey

func (s *Segment) GetKey() string

GetKey returns the string key for the segment.

This method exists in order to conform to interfaces used internally by the SDK.

func (*Segment) GetVersion

func (s *Segment) GetVersion() int

GetVersion returns the version of the segment.

This method exists in order to conform to interfaces used internally by the SDK.

func (*Segment) IsDeleted

func (s *Segment) IsDeleted() bool

IsDeleted returns whether this is a deleted segment placeholder.

This method exists in order to conform to interfaces used internally by the SDK.

func (Segment) MarshalJSON

func (s Segment) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default json.Marshal behavior to provide the same marshalling behavior that is used by NewJSONDataModelSerialization().

func (*Segment) UnmarshalJSON

func (s *Segment) UnmarshalJSON(data []byte) error

UnmarshalJSON overrides the default json.Unmarshal behavior to provide the same unmarshalling behavior that is used by NewJSONDataModelSerialization().

type SegmentRule

type SegmentRule struct {
	// ID is a randomized identifier assigned to each rule when it is created.
	ID string
	// Clauses is a list of test conditions that make up the rule. These are ANDed: every Clause must
	// match in order for the SegmentRule to match.
	Clauses []Clause
	// Weight, if non-negative, defines a percentage rollout in which only a subset of users matching this
	// rule are included in the segment. This is specified as an integer from 0 (0%) to 100000 (100%).
	Weight int
	// BucketBy specifies which user attribute should be used to distinguish between users in a rollout.
	//
	// The default (when BucketBy is empty) is lduser.KeyAttribute, the user's primary key. If you wish to
	// treat users with different keys as the same for rollout purposes as long as they have the same
	// "country" attribute, you would set this to "country" (lduser.CountryAttribute).
	//
	// Rollouts always take the user's "secondary key" attribute into account as well if the user has one.
	BucketBy lduser.UserAttribute
}

SegmentRule describes a single rule within a user segment.

type Target

type Target struct {
	// Values is the set of user keys included in this Target.
	Values []string
	// Variation is the index of the variation to be returned if the user matches one of these keys. This
	// is always a real variation index; it cannot be undefined.
	Variation int
	// contains filtered or unexported fields
}

Target describes a set of users who will receive a specific variation.

type VariationOrRollout

type VariationOrRollout struct {
	// Variation specifies the index of the variation to return. It is undefined (ldvalue.OptionalInt{})
	// if no specific variation is defined.
	Variation ldvalue.OptionalInt
	// Rollout specifies a percentage rollout to be used instead of a specific variation. A rollout is
	// only defined if it has a non-empty Variations list.
	Rollout Rollout
}

VariationOrRollout desscribes either a fixed variation or a percentage rollout.

There is a VariationOrRollout for every FlagRule, and also one in FeatureFlag.Fallthrough which is used if no rules match.

Invariant: one of the variation or rollout must be non-nil.

type WeightedVariation

type WeightedVariation struct {
	// Variation is the index of the variation to be returned if the user is in this bucket. This is
	// always a real variation index; it cannot be undefined.
	Variation int
	// Weight is the proportion of users who should go into this bucket, as an integer from 0 to 100000.
	Weight int
	// Untracked means that users allocated to this variation should not have tracking events sent.
	Untracked bool
}

WeightedVariation describes a fraction of users who will receive a specific variation.

Jump to

Keyboard shortcuts

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