Subchapter 50.15
references/sdk/snippets/go-server-sdk.mdMarkdown2 KBView on GitHub
LDClient, MakeClient (opens in a new tab)The Initialize the client (opens in a new tab) chapter shows MakeClient / MakeCustomClient (and optional ldcontext + NewScopedClient for a scoped client). It does not use Initialized() in that section. The error from MakeClient is what signals construction-time failure (see the “Best practices for error handling” callout in those docs). If you need to branch on “fully ready” after the timeout window, use Initialized (opens in a new tab) or Monitoring SDK status (opens in a new tab)—read MakeClient (opens in a new tab) for how the timeout interacts with returning before the client has finished connecting.
Includes: Minimal onboarding sample aligned with “Go SDK, using LDClient and default configuration” in the docs. For MakeCustomClient, ldcontext, LDScopedClient, or the observability plugin, follow the same page’s larger examples.
package main
import (
"fmt"
"os"
"time"
ld "github.com/launchdarkly/go-server-sdk/v7"
)
func main() {
ldClient, err := ld.MakeClient(os.Getenv("LAUNCHDARKLY_SDK_KEY"), 5*time.Second)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create LaunchDarkly client: %v\n", err)
os.Exit(1)
}
fmt.Println("LaunchDarkly client created.")
// For onboarding purposes only we flush events as soon as
// possible so we quickly detect your connection.
// You don't have to do this in practice because events are automatically flushed.
ldClient.Flush()
}