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:
store, err := ldconsul.NewConsulFeatureStore() if err != nil { ... } config := ld.DefaultConfig config.FeatureStore = store 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 ¶
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.
Types ¶
type FeatureStoreOption ¶
type FeatureStoreOption interface {
// contains filtered or unexported methods
}
FeatureStoreOption is the interface for optional configuration parameters that can be passed to NewConsulFeatureStore. These include UseConfig, Prefix, CacheTTL, and UseLogger.
func Address ¶
func Address(address string) FeatureStoreOption
Address creates an option for NewConsulFeatureStore, to set the address of the Consul server. If placed after Config(), this modifies the previously specified configuration.
store, err := ldconsul.NewConsulFeatureStore(ldconsul.Address("http://consulhost:8100"))
func CacheTTL ¶
func CacheTTL(ttl time.Duration) FeatureStoreOption
CacheTTL creates an option for NewConsulFeatureStore, to specify how long flag data should be cached in memory to avoid rereading it from Consul. If this is zero, the feature store will not use an in-memory cache. The default value is DefaultCacheTTL.
store, err := ldconsul.NewConsulFeatureStore(ldconsul.CacheTTL(30*time.Second))
func Config ¶
func Config(config c.Config) FeatureStoreOption
Config creates an option for NewConsulFeatureStore, to specify an entire configuration for the Consul driver. This overwrites any previous Consul settings that may have been specified.
store, err := ldconsul.NewConsulFeatureStore(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 not specified, a log.Logger is used.
store, err := ldconsul.NewConsulFeatureStore(ldconsul.Logger(myLogger))
func Prefix ¶
func Prefix(prefix string) FeatureStoreOption
Prefix creates an option for NewConsulFeatureStore, to specify a prefix for namespacing the feature store's keys. The default value is DefaultPrefix.
store, err := ldconsul.NewConsulFeatureStore(ldconsul.Prefix("ld-data"))