-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (32 loc) · 864 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"os"
"time"
ld "gopkg.in/launchdarkly/go-client.v4"
)
const (
ENV_KEY = "LD_SDK_KEY"
ENV_USER = "LD_USER"
)
func main() {
/* from env variable LD_SDK_KEY */
sdk_key := os.Getenv(ENV_KEY)
if sdk_key == "" {
panic("Environment variable '" + ENV_KEY + "' required for sample.")
}
user := os.Getenv(ENV_USER)
if user == "" {
panic("Environment variable '" + ENV_USER + "' required for sample.")
}
/* The LD doc doesn't have any reference to the second return, error */
ld_client, _ := ld.MakeClient(sdk_key, 5*time.Second)
/* you'll need t0 create the "test_in_go" fflag in your LD portal */
show_feature, _ := ld_client.BoolVariation("test_in_go", ld.NewUser(user), false)
if show_feature {
fmt.Printf("The feature is enabled!\n")
} else {
fmt.Printf("The feature is disabled\n")
}
ld_client.Close()
}