1 package subsystems 2 3 import ( 4 "io" 5 "time" 6 7 "github.com/launchdarkly/go-sdk-common/v3/ldtime" 8 "github.com/launchdarkly/go-sdk-common/v3/ldvalue" 9 ) 10 11 // BigSegmentsConfiguration encapsulates the SDK's configuration with regard to Big Segments. 12 // 13 // "Big Segments" are a specific type of user segments. For more information, read the LaunchDarkly 14 // documentation about user segments: https://docs.launchdarkly.com/home/users 15 // 16 // See ldcomponents.BigSegmentsConfigurationBuilder for more details on these properties. 17 type BigSegmentsConfiguration interface { 18 // GetStore returns the data store instance that is used for Big Segments data. 19 GetStore() BigSegmentStore 20 21 // GetContextCacheSize returns the value set by BigSegmentsConfigurationBuilder.CacheSize. 22 GetContextCacheSize() int 23 24 // GetContextCacheTime returns the value set by BigSegmentsConfigurationBuilder.CacheTime. 25 GetContextCacheTime() time.Duration 26 27 // GetStatusPollInterval returns the value set by BigSegmentsConfigurationBuilder.StatusPollInterval. 28 GetStatusPollInterval() time.Duration 29 30 // StaleAfter returns the value set by BigSegmentsConfigurationBuilder.StaleAfter. 31 GetStaleAfter() time.Duration 32 } 33 34 // BigSegmentStore is an interface for a read-only data store that allows querying of context 35 // membership in Big Segments. 36 // 37 // "Big Segments" are a specific type of user segments. For more information, read the LaunchDarkly 38 // documentation about user segments: https://docs.launchdarkly.com/home/users 39 type BigSegmentStore interface { 40 io.Closer 41 42 // GetMetadata returns information about the overall state of the store. This method will be 43 // called only when the SDK needs the latest state, so it should not be cached. 44 GetMetadata() (BigSegmentStoreMetadata, error) 45 46 // GetMembership queries the store for a snapshot of the current segment state for a specific 47 // evaluation context. The contextHash is a base64-encoded string produced by hashing the context key 48 // as defined by the Big Segments specification; the store implementation does not need to know the 49 // details of how this is done, because it deals only with already-hashed keys, but the string can 50 // be assumed to only contain characters that are valid in base64. 51 GetMembership(contextHash string) (BigSegmentMembership, error) 52 } 53 54 // BigSegmentStoreMetadata contains values returned by BigSegmentStore.GetMetadata(). 55 type BigSegmentStoreMetadata struct { 56 // LastUpToDate is the timestamp of the last update to the BigSegmentStore. It is zero if 57 // the store has never been updated. 58 LastUpToDate ldtime.UnixMillisecondTime 59 } 60 61 // BigSegmentMembership is the return type of BigSegmentStore.GetContextMembership(). It is associated 62 // with a single evaluation context, and provides the ability to check whether that context is included 63 // in or excluded from any number of Big Segments. 64 // 65 // This is an immutable snapshot of the state for this context at the time GetMembership was 66 // called. Calling GetMembership should not cause the state to be queried again. The object 67 // should be safe for concurrent access by multiple goroutines. 68 type BigSegmentMembership interface { 69 // CheckMembership tests whether the context is explicitly included or explicitly excluded in the 70 // specified segment, or neither. The segment is identified by a segmentRef which is not the 71 // same as the segment key-- it includes the key but also versioning information that the SDK 72 // will provide. The store implementation should not be concerned with the format of this. 73 // 74 // If the context is explicitly included (regardless of whether the context is also explicitly 75 // excluded or not-- that is, inclusion takes priority over exclusion), the method returns an 76 // OptionalBool with a true value. 77 // 78 // If the context is explicitly excluded, and is not explicitly included, the method returns an 79 // OptionalBool with a false value. 80 // 81 // If the context's status in the segment is undefined, the method returns OptionalBool{} with no 82 // value (so calling IsDefined() on it will return false). 83 CheckMembership(segmentRef string) ldvalue.OptionalBool 84 } 85