Documentation
¶
Overview ¶
Package ldconsul provides a Consul-backed feature store for the LaunchDarkly Go SDK.
For more details about how and why you can use a persistent feature store, see: https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store
To use the Consul feature store with the LaunchDarkly client:
factory, err := ldconsul.NewConsulFeatureStoreFactory() if err != nil { ... } config := ld.DefaultConfig config.FeatureStoreFactory = factory client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)
The default Consul configuration uses an address of localhost:8500. To customize any properties of Consul, you can use the Address() or Config() functions.
If you are also using Consul for other purposes, the feature store can coexist with other data as long as you are not using the same keys. By default, the keys used by the feature store will always start with "launchdarkly/"; you can change this to another prefix if desired.
Index ¶
Constants ¶
const ( // DefaultCacheTTL is the amount of time that recently read or updated items will be cached // in memory, unless you specify otherwise with the CacheTTL option. DefaultCacheTTL = 15 * time.Second // DefaultPrefix is a string that is prepended (along with a slash) to all Consul keys used // by the feature store. You can change this value with the Prefix() option. DefaultPrefix = "launchdarkly" )
Variables ¶
This section is empty.
Functions ¶
func NewConsulFeatureStore
deprecated
func NewConsulFeatureStore(options ...FeatureStoreOption) (ld.FeatureStore, error)
NewConsulFeatureStore creates a new Consul-backed feature store with an optional memory cache. You may customize its behavior with any number of FeatureStoreOption values, such as Config, Address, Prefix, CacheTTL, and Logger.
Deprecated: Please use NewConsulFeatureStoreFactory instead.
func NewConsulFeatureStoreFactory ¶
func NewConsulFeatureStoreFactory(options ...FeatureStoreOption) (ld.FeatureStoreFactory, error)
NewConsulFeatureStoreFactory returns a factory function for a Consul-backed feature store with an optional memory cache. You may customize its behavior with any number of FeatureStoreOption values, such as Config, Address, Prefix, CacheTTL, and Logger.
Set the FeatureStoreFactory field in your Config to the returned value. Because this is specified as a factory function, the Consul client is not actually created until you create the SDK client. This also allows it to use the same logging configuration as the SDK, so you do not have to specify the Logger option separately.
Types ¶
type FeatureStoreOption ¶
type FeatureStoreOption interface {
// contains filtered or unexported methods
}
FeatureStoreOption is the interface for optional configuration parameters that can be passed to NewConsulFeatureStoreFactory. These include UseConfig, Prefix, CacheTTL, and UseLogger.
func Address ¶
func Address(address string) FeatureStoreOption
Address creates an option for NewConsulFeatureStoreFactory, to set the address of the Consul server. If placed after Config(), this modifies the previously specified configuration.
factory, err := ldconsul.NewConsulFeatureStoreFactory(ldconsul.Address("http://consulhost:8100"))
func CacheTTL ¶
func CacheTTL(ttl time.Duration) FeatureStoreOption
CacheTTL creates an option for NewConsulFeatureStoreFactory, to specify how long flag data should be cached in memory to avoid rereading it from Consul.
The default value is DefaultCacheTTL. A value of zero disables in-memory caching completely. A negative value means data is cached forever (i.e. it will only be read again from the database if the SDK is restarted). Use the "cached forever" mode with caution: it means that in a scenario where multiple processes are sharing the database, and the current process loses connectivity to LaunchDarkly while other processes are still receiving updates and writing them to the database, the current process will have stale data.
factory, err := ldconsul.NewConsulFeatureStoreFactory(ldconsul.CacheTTL(30*time.Second))
func Config ¶
func Config(config c.Config) FeatureStoreOption
Config creates an option for NewConsulFeatureStoreFactory, to specify an entire configuration for the Consul driver. This overwrites any previous Consul settings that may have been specified.
factory, err := ldconsul.NewConsulFeatureStoreFactory(ldconsul.Config(myConsulConfig))
func Logger ¶
func Logger(logger ld.Logger) FeatureStoreOption
Logger creates an option for NewConsulFeatureStore, to specify where to send log output.
If you use NewConsulFeatureStoreFactory rather than the deprecated constructor, you normally do not need to specify a logger because it will use the same logging configuration as the SDK client.
store, err := ldconsul.NewConsulFeatureStore(ldconsul.Logger(myLogger))
func Prefix ¶
func Prefix(prefix string) FeatureStoreOption
Prefix creates an option for NewConsulFeatureStoreFactory, to specify a prefix for namespacing the feature store's keys. The default value is DefaultPrefix.
factory, err := ldconsul.NewConsulFeatureStoreFactory(ldconsul.Prefix("ld-data"))