Set up Go SDK

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

You can find your server-side SDK keys, mobile keys, and client-side ID on the SDK keys page under Settings.

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