1 package ldmodel 2 3 import ( 4 "github.com/launchdarkly/go-sdk-common/v3/ldattr" 5 "github.com/launchdarkly/go-sdk-common/v3/ldcontext" 6 "github.com/launchdarkly/go-sdk-common/v3/ldvalue" 7 ) 8 9 // Segment describes a group of contexts based on context keys and/or matching rules. 10 type Segment struct { 11 // Key is the unique key of the user segment. 12 Key string 13 // Included is a list of context keys that are always matched by this segment, for the default context kind 14 // ("user"). Other context kinds are covered by IncludedContexts. 15 Included []string 16 // Excluded is a list of user keys that are never matched by this segment, unless the key is also in Included. 17 Excluded []string 18 // IncludedContexts contains sets of individually included contexts for specific context kinds. 19 // 20 // For backward compatibility, the targeting lists are divided up as follows: for the default kind ("user"), 21 // we list the keys in Included, but for all other context kinds we use IncludedContexts. 22 IncludedContexts []SegmentTarget 23 // ExcludedContexts contains sets of individually excluded contexts for specific context kinds. 24 // 25 // For backward compatibility, the targeting lists are divided up as follows: for the default kind ("user"), 26 // we list the keys in Excluded, but for all other context kinds we use ExcludedContexts. 27 ExcludedContexts []SegmentTarget 28 // Salt is a randomized value assigned to this segment when it is created. 29 // 30 // The hash function used for calculating percentage rollouts uses this as a salt to ensure that 31 // rollouts are consistent within each segment but not predictable from one segment to another. 32 Salt string 33 // Rules is a list of rules that may match a context. 34 // 35 // If a context is matched by a Rule, all subsequent Rules in the list are skipped. Rules are ignored 36 // if the context's key was matched by Included, Excluded, IncludedContexts, or ExcludedContexts. 37 Rules []SegmentRule 38 // Unbounded is true if this is a segment whose included/excluded key lists are stored separately and are not 39 // limited in size. 40 // 41 // The name is historical: "unbounded segments" was an earlier name for the product feature that is currently 42 // known as "Big Segments". If Unbounded is true, this is a Big Segment. 43 Unbounded bool 44 // UnboundedContextKind is the context kind associated with the included/excluded key lists if this segment 45 // is a Big Segment. If it is empty, we assume ldcontext.DefaultKind. This field is ignored if Unbounded is 46 // false. 47 // 48 // An empty string value here represents the property being unset (so it will be omitted in 49 // serialization). 50 UnboundedContextKind ldcontext.Kind 51 // Version is an integer that is incremented by LaunchDarkly every time the configuration of the segment is 52 // changed. 53 Version int 54 // Generation is an integer that indicates which set of big segment data is currently active for this segment 55 // key. LaunchDarkly increments it if a segment is deleted and recreated. This value is only meaningful for big 56 // segments. If this field is unset, it means the segment representation used an older schema so the generation 57 // is unknown, in which case matching a big segment is not possible. 58 Generation ldvalue.OptionalInt 59 // Deleted is true if this is not actually a user segment but rather a placeholder (tombstone) for a 60 // deleted segment. This is only relevant in data store implementations. 61 Deleted bool 62 // preprocessedData is created by Segment.Preprocess() to speed up target matching. 63 preprocessed segmentPreprocessedData 64 } 65 66 // SegmentTarget describes a target list within a segment, for a specific context kind. 67 type SegmentTarget struct { 68 // ContextKind is the context kind that this target list applies to. 69 // 70 // LaunchDarkly will normally always set this property, but if it is empty/omitted, it should be 71 // treated as ldcontext.DefaultKind. An empty string value here represents the property being unset 72 // (so it will be omitted in serialization). 73 ContextKind ldcontext.Kind 74 // Values is the set of context keys included in this Target. 75 Values []string 76 // preprocessed is created by PreprocessSegment() to speed up target matching. 77 preprocessed targetPreprocessedData 78 } 79 80 // SegmentRule describes a single rule within a segment. 81 type SegmentRule struct { 82 // ID is a randomized identifier assigned to each rule when it is created. 83 ID string 84 // Clauses is a list of test conditions that make up the rule. These are ANDed: every Clause must 85 // match in order for the SegmentRule to match. 86 Clauses []Clause 87 // Weight, if defined, specifies a percentage rollout in which only a subset of contexts matching this 88 // rule are included in the segment. This is specified as an integer from 0 (0%) to 100000 (100%). 89 Weight ldvalue.OptionalInt 90 // BucketBy specifies which context attribute should be used to distinguish between contexts in a rollout. 91 // This property is ignored if Weight is undefined. 92 // 93 // The default (when BucketBy is empty) is ldattr.KeyAttr, the context's primary key. If you wish to 94 // treat contexts with different keys as the same for rollout purposes as long as they have the same 95 // "country" attribute, you would set this to "country". 96 // 97 // Rollouts always take the context's "secondary key" attribute into account as well if there is one. 98 // 99 // An empty ldattr.Ref{} value here represents the property being unset (so it will be omitted in 100 // serialization). That is different from setting it explicitly to "", which is an invalid attribute 101 // reference. 102 BucketBy ldattr.Ref 103 // RolloutContextKind specifies what kind of context the key (or other attribute if BucketBy is set) 104 // should be used to get attributes when computing a rollout. This property is ignored if Weight is 105 // undefined. If unset, it defaults to ldcontext.DefaultKind. 106 // 107 // An empty string value here represents the property being unset (so it will be omitted in 108 // serialization). 109 RolloutContextKind ldcontext.Kind 110 } 111