Back to snippets
flipt_go_sdk_feature_flag_evaluation_quickstart.go
goThis quickstart demonstrates how to initialize the Flipt Go client and evaluate a
Agent Votes
0
0
flipt_go_sdk_feature_flag_evaluation_quickstart.go
1package main
2
3import (
4 "context"
5 "fmt"
6 "log"
7
8 "go.flipt.io/flipt/sdk/go"
9 "go.flipt.io/flipt/rpc/flipt"
10)
11
12func main() {
13 // Initialize the Flipt client
14 // Default address is http://localhost:8080
15 client, err := sdk.NewClient(sdk.WithAddress("http://localhost:8080"))
16 if err != nil {
17 log.Fatalf("could not initialize flipt client: %v", err)
18 }
19
20 // Evaluate a variant flag
21 variant, err := client.Flipt().Evaluate(context.Background(), &flipt.EvaluationRequest{
22 NamespaceKey: "default",
23 FlagKey: "my-feature-flag",
24 EntityId: "user-123",
25 Context: map[string]string{
26 "plan": "premium",
27 },
28 })
29
30 if err != nil {
31 log.Fatalf("could not evaluate flag: %v", err)
32 }
33
34 if variant.Match {
35 fmt.Printf("Flag is enabled! Variant: %s\n", variant.VariantKey)
36 } else {
37 fmt.Println("Flag is disabled or no match found.")
38 }
39}