You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-1Lines changed: 39 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -29,12 +29,48 @@ To follow along with our test code sample, make sure you’ve:
29
29
-[Created a server SDK key and made a copy of it](https://ngdocs.harness.io/article/1j7pdkqh7j-create-a-feature-flag#step_3_create_an_sdk_key)
30
30
31
31
32
-
###Install the SDK
32
+
## Install the SDK
33
33
Install the golang SDK using go
34
34
```golang
35
35
go get github.com/harness/ff-golang-server-sdk
36
36
```
37
37
38
+
## Initialize the SDK
39
+
### Non-blocking Initialization (Default)
40
+
By default, when initializing the Harness Feature Flags client, the initialization process is non-blocking. This means that the client creation call will return immediately, allowing your application to continue its startup process without waiting for the client to be fully initialized. Here’s an example of creating a non-blocking client:
41
+
42
+
```go
43
+
client, err:= harness.NewCfClient(apiKey)
44
+
```
45
+
In this scenario, the client will initialize in the background, making it possible to use the client even if it hasn’t finished initializing.
46
+
Be mindful that if you attempt to evaluate a feature flag before the client has fully initialized, it will return the default value provided in the evaluation call.
47
+
48
+
### Blocking Initialization
49
+
In some cases, you may want your application to wait for the client to finish initializing before continuing. To achieve this, you can use the `WithWaitForInitialized` option, which will block until the client is fully initialized. Example usage:
log.ErrorF("could not connect to FF servers %s", err)
56
+
}
57
+
```
58
+
59
+
60
+
In this example, WaitForInitialized will block for up to 5 authentication attempts. If the client is not initialized within 5 authentication attempts, it will return an error.
61
+
62
+
This can be useful if you need to unblock after a certain time. **NOTE**: if you evaluate a feature flag in this state
63
+
the default variation will be returned.
64
+
65
+
```go
66
+
// Try to authenticate only 5 times before returning a result
log.Fatalf("client did not initialize in time: %s", err)
71
+
}
72
+
```
73
+
38
74
### Code Sample
39
75
The following is a complete code example that you can use to test the `harnessappdemodarkmode` Flag you created on the Harness Platform. When you run the code it will:
docker run -e FF_API_KEY=$FF_API_KEY -v $(pwd):/app -w /app golang:1.17 go run examples/getting_started.go
115
151
```
116
152
153
+
154
+
117
155
### Additional Reading
118
156
119
157
For further examples and config options, see the [Golang SDK Reference](https://ngdocs.harness.io/article/4c8wljx60w-feature-flag-sdks-go-application).
c.config.Logger.Error("Authentication failed with a non-retryable error: '%s %s' Default variations will now be served", nonRetryableAuthError.StatusCode, nonRetryableAuthError.Message)
285
+
returnerr
286
+
}
287
+
288
+
// -1 is the default maxAuthRetries option and indicates there should be no max attempts
0 commit comments