Set up Go SDK

LaunchDarkly onboarding is not available in federal environments
To learn more, read LaunchDarkly in federal environments.

Install the package

  • If you are using the standard Go modules system, import the SDK packages in your code and go build will automatically download them. The SDK and its dependencies are modules.

  • Alternatively, you can run the following command:
Shell
$go get github.com/launchdarkly/go-server-sdk/v7

Initialize the SDK

Go SDK initialization
1package main
2
3import (
4 "fmt"
5 "os"
6 "time"
7
8 "github.com/launchdarkly/go-sdk-common/v3/ldcontext"
9 ld "github.com/launchdarkly/go-server-sdk/v7"
10)
11
12func main() {
13 // This is your LaunchDarkly SDK key.
14 // Never hardcode your SDK key in production.
15 ldClient, _ := ld.MakeClient("YOUR_SDK_KEY", 5*time.Second)
16 if ldClient.Initialized() {
17 fmt.Printf("SDK successfully initialized!")
18 } else {
19 fmt.Printf("SDK failed to initialize")
20 os.Exit(1)
21 }
22
23 // For onboarding purposes only we flush events as soon as
24 // possible so we quickly detect your connection.
25 // You don't have to do this in practice because events are automatically flushed.
26 ldClient.Flush()
27}

You can find your server-side SDK key, client-side ID, and mobile key in the “Resources” section of the help menu. Click the help icon at the bottom left corner of the LaunchDarkly UI, then choose SDK keys:

The SDK keys option in the help menu.

The SDK keys option in the help menu.

To learn more, read Initialize the client in the Go SDK reference guide.