Documentation ¶
Overview ¶
Package ldconsul provides a Consul-backed persistent data store for the LaunchDarkly Go SDK.
For more details about how and why you can use a persistent data store, see: https://docs.launchdarkly.com/sdk/features/storing-data/consul#go
To use the Consul data store with the LaunchDarkly client:
import ldconsul "github.com/launchdarkly/go-server-sdk-consul/v3" config := ld.Config{ DataStore: ldcomponents.PersistentDataStore(ldconsul.DataStore()), } client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)
The default Consul configuration uses an address of localhost:8500. You may customize the configuration by using the methods of the ldconsul.DataStoreBuilder returned by ldconsul.DataStore(). For example:
config := ld.Config{ DataStore: ldcomponents.PersistentDataStore( ldconsul.DataStore().Address("my-consul-hostname"), ).CacheSeconds(30), }
Note that CacheSeconds() is not a method of ldconsul.DataStoreBuilder, but rather a method of ldcomponents.PersistentDataStore(), because the caching behavior is provided by the SDK for all database integrations.
If you are also using Consul for other purposes, the data store can coexist with other data as long as you are not using the same keys. By default, the keys used by the data store will always start with "launchdarkly/"; you can change this to another prefix if desired.
Index ¶
- Constants
- type DataStoreBuilder
- func (b *DataStoreBuilder) Address(address string) *DataStoreBuilder
- func (b *DataStoreBuilder) Build(context subsystems.ClientContext) (subsystems.PersistentDataStore, error)
- func (b *DataStoreBuilder) Config(consulConfig c.Config) *DataStoreBuilder
- func (b *DataStoreBuilder) DescribeConfiguration() ldvalue.Value
- func (b *DataStoreBuilder) Prefix(prefix string) *DataStoreBuilder
Constants ¶
const ( // DefaultPrefix is a string that is prepended (along with a slash) to all Consul keys used // by the data store. You can change this value with the Prefix() option. DefaultPrefix = "launchdarkly" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataStoreBuilder ¶
type DataStoreBuilder struct {
// contains filtered or unexported fields
}
DataStoreBuilder is a builder for configuring the Consul-based persistent data store.
Obtain an instance of this type by calling DataStore(). After calling its methods to specify any desired custom settings, wrap it in a PersistentDataStoreBuilder by calling ldcomponents.PersistentDataStore(), and then store this in the SDK configuration's DataStore field.
Builder calls can be chained, for example:
config.DataStore = ldconsul.DataStore().Address("hostname:8500).Prefix("prefix")
You do not need to call the builder's CreatePersistentDataStore() method yourself to build the actual data store; that will be done by the SDK.
func DataStore ¶
func DataStore() *DataStoreBuilder
DataStore returns a configurable builder for a Consul-backed data store.
func (*DataStoreBuilder) Address ¶
func (b *DataStoreBuilder) Address(address string) *DataStoreBuilder
Address sets the address of the Consul server. If placed after Config(), this modifies the preivously specified configuration.
func (*DataStoreBuilder) Build ¶
func (b *DataStoreBuilder) Build(context subsystems.ClientContext) (subsystems.PersistentDataStore, error)
Build is called internally by the SDK.
func (*DataStoreBuilder) Config ¶
func (b *DataStoreBuilder) Config(consulConfig c.Config) *DataStoreBuilder
Config specifies an entire configuration for the Consul driver. This overwrites any previous Consul settings that may have been specified.
func (*DataStoreBuilder) DescribeConfiguration ¶
func (b *DataStoreBuilder) DescribeConfiguration() ldvalue.Value
DescribeConfiguration is used internally by the SDK to inspect the configuration.
func (*DataStoreBuilder) Prefix ¶
func (b *DataStoreBuilder) Prefix(prefix string) *DataStoreBuilder
Prefix specifies a prefix for namespacing the data store's keys. The default value is DefaultPrefix.