Categorygithub.com/launchdarkly/go-server-sdk-consul/v3
modulepackage
3.0.0
Repository: https://github.com/launchdarkly/go-server-sdk-consul.git
Documentation: pkg.go.dev

# README

LaunchDarkly Server-side SDK for Go - Consul integration

Circle CI Documentation

This library provides a Consul-backed persistence mechanism (data store) for the LaunchDarkly Go SDK, replacing the default in-memory data store. It uses the standard Consul Go client.

This version of the library requires at least version 6.0.0 of the LaunchDarkly Go SDK; for versions of the library to use with earlier SDK versions, see the changelog.

The minimum Go version is 1.18.

For more information, see also: Using Consul as a persistent feature store.

Quick setup

This assumes that you have already installed the LaunchDarkly Go SDK.

  1. Import the LaunchDarkly SDK packages and the package for this library:
import (
    ld "github.com/launchdarkly/go-server-sdk/v7"
    "github.com/launchdarkly/go-server-sdk/v7/ldcomponents"
    ldconsul "github.com/launchdarkly/go-server-sdk-consul/v3"
)
  1. When configuring your SDK client, add the Consul data store as a PersistentDataStore. You may specify any custom Consul options using the methods of ConsulDataStoreBuilder. For instance, to customize the Consul hostname:
    var config ld.Config{}
    config.DataStore = ldcomponents.PersistentDataStore(
        ldconsul.DataStore().Address("my-consul-host"),
    )

By default, the store will try to connect to a local Consul instance on port 8500.

Caching behavior

The LaunchDarkly SDK has a standard caching mechanism for any persistent data store, to reduce database traffic. This is configured through the SDK's PersistentDataStoreBuilder class as described the SDK documentation. For instance, to specify a cache TTL of 5 minutes:

    var config ld.Config{}
    config.DataStore = ldcomponents.PersistentDataStore(
        ldconsul.DataStore(),
    ).CacheMinutes(5)

Data size limitation

Consul does not support storing values greater than 512KB. Therefore, this integration will not work if the JSON representation of any feature flag or user segment exceeds that size.

To see the JSON representations of all flags and segments, query https://app.launchdarkly.com/sdk/latest-all with your SDK key in an Authorization header.

LaunchDarkly overview

LaunchDarkly is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. Get started using LaunchDarkly today!

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read our documentation for a complete list.
  • Explore LaunchDarkly

# Functions

DataStore returns a configurable builder for a Consul-backed data store.

# Constants

DefaultPrefix is a string that is prepended (along with a slash) to all Consul keys used by the data store.

# Structs

DataStoreBuilder is a builder for configuring the Consul-based persistent data store.