Categorygithub.com/launchdarkly/go-client
modulepackage
0.0.0-20190708190747-0933bec82397
Repository: https://github.com/launchdarkly/go-client.git
Documentation: pkg.go.dev

# README

LaunchDarkly SDK for Go

Circle CI

Important note

As mentioned in the repository changelog, the go-client project has been renamed to go-server-sdk. All future releases will be made from the new repository. Please consider updating your import paths and filing potential requests in that repository's issue tracker.

Go runtime compatibility

This version of the LaunchDarkly SDK has been tested with Go 1.8 through 1.10.

Quick setup

  1. Install the SDK with the go tool:
go get gopkg.in/launchdarkly/go-client.v4
  1. Import the LaunchDarkly client:
import ld "gopkg.in/launchdarkly/go-client.v4"
  1. Create a new LDClient with your SDK key:
ldClient, err := ld.MakeClient("YOUR_SDK_KEY", 5*time.Second)
if err != nil {
    log.Fatalf("Error creating launch darkly client: %s", err)
}
defer ldClient.Close()

If you are reusing a global instance you probably want to not defer ldClient.Close() but instead close it when the application exits.

HTTPS proxy

Go's standard HTTP library provides built-in support for the use of an HTTPS proxy. If the HTTPS_PROXY environment variable is present then the SDK will proxy all network requests through the URL provided.

How to set the HTTPS_PROXY environment variable on Mac/Linux systems:

export HTTPS_PROXY=https://web-proxy.domain.com:8080

How to set the HTTPS_PROXY environment variable on Windows systems:

set HTTPS_PROXY=https://web-proxy.domain.com:8080

If your proxy requires authentication then you can prefix the URN with your login information:

export HTTPS_PROXY=http://user:[email protected]:8080

or

set HTTPS_PROXY=http://user:[email protected]:8080

Your first feature flag

  1. Create a new feature flag on your dashboard
  2. In your application code, use the feature's key to check whether the flag is on for each user:
key := "[email protected]"
showFeature, _ := ldClient.BoolVariation("your.flag.key", ld.User{Key: &key}, false)
if showFeature {
    // application code to show the feature
} else {
    // the code to run if the feature is off
}

Database integrations

Feature flag data can be kept in a persistent store using Redis, Consul, or DynamoDB. These adapters are implemented in the subpackages redis, ldconsul, and lddynamodb; to use them, call the New...FeatureStore function provided by the subpackage, and put the returned object in the FeatureStore field of your client configuration. See the subpackages and the SDK reference guide for more information.

Using flag data from a file

For testing purposes, the SDK can be made to read feature flag state from a file or files instead of connecting to LaunchDarkly. See ldfiledata and ldfilewatch for more details.

Learn more

Check out our documentation for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the complete reference guide for this SDK and the API reference.

Testing

We run integration tests for all our SDKs using a centralized test harness. This approach gives us the ability to test for consistency across SDKs, as well as test networking behavior in a long-running application. These tests cover each method in the SDK, and verify that event sending, flag evaluation, stream reconnection, and other aspects of the SDK all behave correctly.

Contributing

We encourage pull-requests and other contributions from the community. We've also published an SDK contributor's guide that provides a detailed explanation of how our SDKs work.

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. Check out our documentation for a complete list.
  • Explore LaunchDarkly

# Packages

Package ldconsul provides a Consul-backed feature store for the LaunchDarkly Go SDK.
Package lddynamodb provides a DynamoDB-backed feature store for the LaunchDarkly Go SDK.
Package ldfiledata allows the LaunchDarkly client to read feature flag data from a file.
Package ldfilewatch allows the LaunchDarkly client to read feature flag data from a file, with automatic reloading.
Package redis provides a Redis-backed persistent feature store for the LaunchDarkly Go SDK.
No description provided by the author
Package utils contains support code that most users of the SDK will not need to access directly.

# Functions

MakeAllVersionedDataMap returns a map of version objects grouped by namespace that can be used to initialize a feature store.
MakeClient creates a new client instance that connects to LaunchDarkly with the default configuration.
MakeCustomClient creates a new client instance that connects to LaunchDarkly with a custom configuration.
NewAnonymousUser creates a new anonymous user identified by the given key.
NewCustomEvent constructs a new custom event, but does not send it.
NewDefaultEventProcessor creates an instance of the default implementation of analytics event processing.
NewFeatureRequestEvent creates a feature request event.
NewIdentifyEvent constructs a new identify event, but does not send it.
NewInMemoryFeatureStore creates a new in-memory FeatureStore instance.
NewUser creates a new user identified by the given key.
ParseFloat64 parses a numeric value as float64 from a string or another numeric type.
ParseTime converts any of the following into a pointer to a time.Time value: RFC3339/ISO8601 timestamp (example: 2016-04-16T17:09:12.759-07:00) Unix epoch milliseconds as string Unix milliseconds as number Passing in a time.Time value will return a pointer to the input value.
ToJsonRawMessage converts input to a *json.RawMessage if possible.

# Constants

Event types.
EvalErrorClientNotReady indicates that the caller tried to evaluate a flag before the client had successfully initialized.
EvalErrorException indicates that an unexpected error stopped flag evaluation; check the log for details.
EvalErrorFlagNotFound indicates that the caller provided a flag key that did not match any known flag.
EvalErrorMalformedFlag indicates that there was an internal inconsistency in the flag data, e.g.
EvalErrorUserNotSpecified indicates that the caller passed a user without a key for the user parameter.
EvalErrorWrongType indicates that the result value was not of the requested type, e.g.
EvalReasonError indicates that the flag could not be evaluated, e.g.
EvalReasonFallthrough indicates that the flag was on but the user did not match any targets or rules.
EvalReasonOff indicates that the flag was off and therefore returned its configured off value.
EvalReasonPrerequisiteFailed indicates that the flag was considered off because it had at least one prerequisite flag that either was off or did not return the desired variation.
EvalReasonRuleMatch indicates that the user matched one of the flag's rules.
EvalReasonTargetMatch indicates that the user key was specifically targeted for this flag.
Event types.
Event types.
Event types.
Event types.
SDK endpoints.
SDK endpoints.
SDK endpoints.
MinimumPollInterval describes the minimum value for Config.PollInterval.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
List of available operators.
Event types.
Version is the client version.

# Variables

ClientSideOnly - when passed to LDClient.AllFlagsState() - specifies that only flags marked for use with the client-side SDK should be included in the state object.
DefaultConfig provides the default configuration options for the LaunchDarkly client.
DetailsOnlyForTrackedFlags - when passed to LDClient.AllFlagsState() - specifies that any flag metadata that is normally only used for event generation - such as flag versions and evaluation reasons - should be omitted for any flag that does not have event tracking or debugging turned on.
Initialization errors.
Initialization errors.
Initialization errors.
Features is convenience variable to access an instance of FeatureFlagVersionedDataKind.
OpsList is the list of available operators.
Segments is convenience variable to access an instance of SegmentVersionedDataKind.
VersionedDataKinds is a list of supported VersionedDataKind's.
WithReasons - when passed to LDClient.AllFlagsState() - specifies that evaluation reasons should be included in the state object.

# Structs

BaseEvent provides properties common to all events.
Clause describes an individual cluuse within a targeting rule.
Config exposes advanced configuration options for the LaunchDarkly client.
CustomEvent is generated by calling the client's Track method.
DerivedAttribute is an entry in a Derived attribute map and is for internal use by LaunchDarkly only.
EvalResult describes the value and variation index that are the result of flag evaluation.
EvaluationDetail is an object returned by LDClient.VariationDetail, combining the result of a flag evaluation with an explanation of how it was calculated.
EvaluationReasonContainer is used internally in cases where LaunchDarkly needs to unnmarshal an EvaluationReason value from JSON.
EvaluationReasonError means that the flag could not be evaluated, e.g.
EvaluationReasonFallthrough means that the flag was on but the user did not match any targets or rules.
EvaluationReasonOff means that the flag was off and therefore returned its configured off value.
EvaluationReasonPrerequisiteFailed means that the flag was considered off because it had at least one prerequisite flag that either was off or did not return the desired variation.
EvaluationReasonRuleMatch means that the user matched one of the flag's rules.
EvaluationReasonTargetMatch means that the user key was specifically targeted for this flag.
Explanation is an obsolete type that is used by the deprecated EvaluateExplain method.
Feature describes a Legacy (v1) feature.
FeatureFlag describes an individual feature flag.
FeatureFlagsState is a snapshot of the state of all feature flags with regard to a specific user, generated by calling LDClient.AllFlagsState().
FeatureFlagVersionedDataKind implements VersionedDataKind and provides methods to build storage engine for flags.
FeatureRequestEvent is generated by evaluating a feature flag or one of a flag's prerequisites.
HttpStatusError describes an http error.
IdentifyEvent is generated by calling the client's Identify method.
IndexEvent is generated internally to capture user details from other events.
InMemoryFeatureStore is a memory based FeatureStore implementation, backed by a lock-striped map.
LDClient is the LaunchDarkly client.
Prerequisite describes a requirement that another feature flag return a specific variation.
Rollout describes how users will be bucketed into variations during a percentage rollout.
Rule expresses a set of AND-ed matching conditions for a user, along with either a fixed variation or a set of rollout percentages.
Segment describes a group of users.
SegmentExplanation describes a rule that determines whether a user was included in or excluded from a segment.
SegmentRule describes a set of clauses that.
SegmentVersionedDataKind implements VersionedDataKind and provides methods to build storage engine for segments.
Target describes a set of users who will receive a specific variation.
TargetRule describes an individual targeting rule.
A User contains specific attributes of a user browsing your site.
Variation describes what value to return for a user.
VariationOrRollout contains either the fixed variation or percent rollout to serve.
WeightedVariation describes a fraction of users who will receive a specific variation.

# Interfaces

EvaluationReason describes the reason that a flag evaluation producted a particular value.
An Event represents an analytics event generated by the client, which will be passed to the EventProcessor.
EventProcessor defines the interface for dispatching analytics events.
FeatureStore is an interface describing a structure that maintains the live collection of features and related objects.
FlagsStateOption is the type of optional parameters that can be passed to LDClient.AllFlagsState.
Logger is a generic logger interface.
UpdateProcessor describes the interface for an object that receives feature flag data.
VersionedData is a common interface for string-keyed, versioned objects such as feature flags.
VersionedDataKind describes a kind of VersionedData objects that may exist in a store.

# Type aliases

EvalErrorKind defines the possible values of the ErrorKind property of EvaluationReason.
EvalReasonKind defines the possible values of the Kind property of EvaluationReason.
Operator describes an operator for a clause.
UpdateProcessorFactory is a function that creates an UpdateProcessor.