Documentation ¶
Overview ¶
Package utils contains support code that most users of the SDK will not need to access directly. However, they may be useful for anyone developing custom integrations.
Index ¶
- func UnmarshalItem(kind ld.VersionedDataKind, raw []byte) (ld.VersionedData, error)
- type FeatureStoreCore
- type FeatureStoreCoreBase
- type FeatureStoreWrapper
- func (w *FeatureStoreWrapper) All(kind ld.VersionedDataKind) (map[string]ld.VersionedData, error)
- func (w *FeatureStoreWrapper) Delete(kind ld.VersionedDataKind, key string, version int) error
- func (w *FeatureStoreWrapper) Get(kind ld.VersionedDataKind, key string) (ld.VersionedData, error)
- func (w *FeatureStoreWrapper) Init(allData map[ld.VersionedDataKind]map[string]ld.VersionedData) error
- func (w *FeatureStoreWrapper) Initialized() bool
- func (w *FeatureStoreWrapper) Upsert(kind ld.VersionedDataKind, item ld.VersionedData) error
- type NonAtomicFeatureStoreCore
- type StoreCollection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnmarshalItem ¶
func UnmarshalItem(kind ld.VersionedDataKind, raw []byte) (ld.VersionedData, error)
UnmarshalItem attempts to unmarshal an entity that has been stored as JSON in a FeatureStore. The kind parameter indicates what type of entity is expected.
Types ¶
type FeatureStoreCore ¶
type FeatureStoreCore interface { FeatureStoreCoreBase // InitInternal replaces the entire contents of the data store. This should be done // atomically (i.e. within a transaction). InitInternal(map[ld.VersionedDataKind]map[string]ld.VersionedData) error }
FeatureStoreCore is an interface for a simplified subset of the functionality of ldclient.FeatureStore, to be used in conjunction with FeatureStoreWrapper. This allows developers of custom FeatureStore implementations to avoid repeating logic that would commonly be needed in any such implementation, such as caching. Instead, they can implement only FeatureStoreCore and then call NewFeatureStoreWrapper.
This interface assumes that the feature store can update the data set atomically. If not, use NonAtomicFeatureStoreCore instead. FeatureStoreCoreBase defines the common methods.
type FeatureStoreCoreBase ¶
type FeatureStoreCoreBase interface { // GetInternal queries a single item from the data store. The kind parameter distinguishes // between different categories of data (flags, segments) and the key is the unique key // within that category. If no such item exists, the method should return (nil, nil). // It should not attempt to filter out any items based on their Deleted property, nor to // cache any items. GetInternal(kind ld.VersionedDataKind, key string) (ld.VersionedData, error) // GetAllInternal queries all items in a given category from the data store, returning // a map of unique keys to items. It should not attempt to filter out any items based // on their Deleted property, nor to cache any items. GetAllInternal(kind ld.VersionedDataKind) (map[string]ld.VersionedData, error) // UpsertInternal adds or updates a single item. If an item with the same key already // exists, it should update it only if the new item's GetVersion() value is greater // than the old one. It should return the final state of the item, i.e. if the update // succeeded then it returns the item that was passed in, and if the update failed due // to the version check then it returns the item that is currently in the data store // (this ensures that caching works correctly). // // Note that deletes are implemented by using UpsertInternal to store an item whose // Deleted property is true. UpsertInternal(kind ld.VersionedDataKind, item ld.VersionedData) (ld.VersionedData, error) // InitializedInternal returns true if the data store contains a complete data set, // meaning that InitInternal has been called at least once. In a shared data store, it // should be able to detect this even if InitInternal was called in a different process, // i.e. the test should be based on looking at what is in the data store. The method // does not need to worry about caching this value; FeatureStoreWrapper will only call // it when necessary. InitializedInternal() bool // GetCacheTTL returns the length of time that data should be retained in an in-memory // cache. This cache is maintained by FeatureStoreWrapper. If GetCacheTTL returns zero, // there will be no cache. GetCacheTTL() time.Duration }
FeatureStoreCoreBase defines methods that are common to the FeatureStoreCore and NonAtomicFeatureStoreCore interfaces.
type FeatureStoreWrapper ¶
type FeatureStoreWrapper struct {
// contains filtered or unexported fields
}
FeatureStoreWrapper is a partial implementation of ldclient.FeatureStore that delegates basic functionality to an instance of FeatureStoreCore. It provides optional caching, and will automatically provide the proper data ordering when using NonAtomicFeatureStoreCoreInitialization.
func NewFeatureStoreWrapper ¶
func NewFeatureStoreWrapper(core FeatureStoreCore) *FeatureStoreWrapper
NewFeatureStoreWrapper creates an instance of FeatureStoreWrapper that wraps an instance of FeatureStoreCore.
func NewNonAtomicFeatureStoreWrapper ¶
func NewNonAtomicFeatureStoreWrapper(core NonAtomicFeatureStoreCore) *FeatureStoreWrapper
NewNonAtomicFeatureStoreWrapper creates an instance of FeatureStoreWrapper that wraps an instance of NonAtomicFeatureStoreCore.
func (*FeatureStoreWrapper) All ¶
func (w *FeatureStoreWrapper) All(kind ld.VersionedDataKind) (map[string]ld.VersionedData, error)
All retrieves all items of the specified kind, with optional caching.
func (*FeatureStoreWrapper) Delete ¶
func (w *FeatureStoreWrapper) Delete(kind ld.VersionedDataKind, key string, version int) error
Delete deletes an item, with optional caching.
func (*FeatureStoreWrapper) Get ¶
func (w *FeatureStoreWrapper) Get(kind ld.VersionedDataKind, key string) (ld.VersionedData, error)
Get retrieves a single item by key, with optional caching.
func (*FeatureStoreWrapper) Init ¶
func (w *FeatureStoreWrapper) Init(allData map[ld.VersionedDataKind]map[string]ld.VersionedData) error
Init performs an update of the entire data store, with optional caching.
func (*FeatureStoreWrapper) Initialized ¶
func (w *FeatureStoreWrapper) Initialized() bool
Initialized returns true if the feature store contains a data set. To avoid calling the underlying implementation any more often than necessary (since Initialized is called often), FeatureStoreWrapper uses the following heuristic: 1. Once we have received a true result from InitializedInternal, we always return true. 2. If InitializedInternal returns false, and we have a cache, we will cache that result so we won't call it any more frequently than the cache TTL.
func (*FeatureStoreWrapper) Upsert ¶
func (w *FeatureStoreWrapper) Upsert(kind ld.VersionedDataKind, item ld.VersionedData) error
Upsert updates or adds an item, with optional caching.
type NonAtomicFeatureStoreCore ¶
type NonAtomicFeatureStoreCore interface { FeatureStoreCoreBase // InitCollectionsInternal replaces the entire contents of the data store. The SDK will // pass a data set with a defined ordering; the collections (kinds) should be processed in // the specified order, and the items within each collection should be written in the // specified order. The store should delete any obsolete items only after writing all of // the items provided. InitCollectionsInternal(allData []StoreCollection) error }
NonAtomicFeatureStoreCore is an interface for a limited subset of the functionality of ldclient.FeatureStore, to be used in conjunction with FeatureStoreWrapper. This allows developers of custom FeatureStore implementations to avoid repeating logic that would commonly be needed in any such implementation, such as caching. Instead, they can implement only FeatureStoreCore and then call NewFeatureStoreWrapper.
This interface assumes that the feature store cannot update the data set atomically and will require the SDK to specify the order of operations. If atomic updates are possible, then use FeatureStoreCore instead. FeatureStoreCoreBase defines the common methods.
Note that this is somewhat different from the way the LaunchDarkly SDK addresses the atomicity issue on most other platforms. There, the feature stores just have one interface, which always receives the data as a map, but the SDK can control the iteration order of the map. That isn't possible in Go where maps never have a defined iteration order.
type StoreCollection ¶
type StoreCollection struct { Kind ld.VersionedDataKind Items []ld.VersionedData }
StoreCollection is used by the NonAtomicFeatureStoreCore interface.