Skip to content

Commit 54ed4be

Browse files
golang bump to v6; adds initialization instructions (#498)
* golang bump to v6; adds initialization instructions * pre and post instructions * Update docs/sdks/server-sdks/go.md Co-authored-by: Oleksii Shmalko <[email protected]> --------- Co-authored-by: Oleksii Shmalko <[email protected]>
1 parent 72ed82e commit 54ed4be

File tree

1 file changed

+37
-6
lines changed
  • docs/sdks/server-sdks

1 file changed

+37
-6
lines changed

docs/sdks/server-sdks/go.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ In your `go.mod`, add the SDK package as a dependency:
1414

1515
```
1616
require (
17-
github.com/Eppo-exp/golang-sdk/v5
17+
github.com/Eppo-exp/golang-sdk/v6
1818
)
1919
```
2020

2121
Or you can install the SDK from the command line with:
2222

2323
```
24-
go get github.com/Eppo-exp/golang-sdk/v5
24+
go get github.com/Eppo-exp/golang-sdk/v6
2525
```
2626

2727
## 2. Initialize the SDK
@@ -31,7 +31,7 @@ Initialize the SDK with a SDK key, which can be generated in the Eppo interface.
3131
```go
3232

3333
import (
34-
"github.com/Eppo-exp/golang-sdk/v5/eppoclient"
34+
"github.com/Eppo-exp/golang-sdk/v6/eppoclient"
3535
)
3636

3737
var eppoClient = &eppoclient.EppoClient{}
@@ -40,11 +40,41 @@ func main() {
4040
eppoClient, err = eppoclient.InitClient(eppoclient.Config{
4141
SdkKey: "<your_sdk_key>",
4242
})
43+
44+
select {
45+
case <-client.Initialized():
46+
case <-time.After(2 * time.Second):
47+
log.Warn("Timed out waiting for Eppo SDK to initialize")
48+
}
4349
}
4450
```
4551

4652
After initialization, the SDK begins polling Eppo's API at regular intervals to retrieve the most recent experiment configurations such as variation values and traffic allocation. The SDK stores these configurations in memory so that assignments thereafter are effectively instant. For more information, see the [architecture overview](/sdks/architecture/overview) page.
4753

54+
### Waiting for initialization
55+
56+
Depending on your server application's lifecycle, you may need to wait for the SDK to initialize before making assignments
57+
58+
Starting with the `6.1.0` tag, the `Initialized` channel is provided to facilitate this and can optionally be used with a timeout to allow you application to continue.
59+
60+
Before this tag, the SDK was initialized asynchronously and assignments could be made immediately but will not be guaranteed to have the most recent experiment configurations, returning the `DEFAULT-VALUE` if the SDK was not initialized in time. If this is not desired in your application, a suggested approach on older versions is to introduce a brief delay after startup to allow the SDK to initialize before making assignments.
61+
62+
```go
63+
import (
64+
"time"
65+
)
66+
67+
func main() {
68+
eppoClient, err = eppoclient.InitClient(eppoclient.Config{
69+
SdkKey: "<your_sdk_key>",
70+
})
71+
72+
time.Sleep(2 * time.Second)
73+
74+
variation, err := eppoClient.GetStringAssignment("<FLAG-KEY>", "<SUBJECT-KEY>", <TARGETING-ATTRIBUTES>, <DEFAULT-VALUE>);
75+
}
76+
```
77+
4878
### Define an assignment logger (experiment assignment only)
4979

5080
If you are using the Eppo SDK for experiment assignment (i.e randomization), pass in a callback logging function to the `InitClient` function on SDK initialization. The SDK invokes the callback to capture assignment data whenever a variation is assigned.
@@ -63,7 +93,7 @@ Example implementation:
6393

6494
```go
6595
import (
66-
"github.com/Eppo-exp/golang-sdk/v5/eppoclient"
96+
"github.com/Eppo-exp/golang-sdk/v6/eppoclient"
6797
"gopkg.in/segmentio/analytics-go.v3"
6898
)
6999

@@ -86,7 +116,7 @@ func main() {
86116
client := analytics.New("YOUR_WRITE_KEY")
87117
defer client.Close()
88118

89-
eppoClient = eppoclient.InitClient(eppoclient.Config{
119+
eppoClient, _ = eppoclient.InitClient(eppoclient.Config{
90120
SdkKey: "<your_sdk_key>",
91121
AssignmentLogger: &ExampleAssignmentLogger{
92122
client: client,
@@ -120,7 +150,7 @@ Assigning users to flags or experiments with a single `GetStringAssignment` func
120150

121151
```go
122152
import (
123-
"github.com/Eppo-exp/golang-sdk/v5/eppoclient"
153+
"github.com/Eppo-exp/golang-sdk/v6/eppoclient"
124154
)
125155

126156
var eppoClient = &eppoclient.EppoClient{} // in global scope
@@ -144,6 +174,7 @@ GetNumericAssignment(...) (float64, error)
144174
GetIntegerAssignment(...) (int, error)
145175
GetStringAssignment(...) (string, error)
146176
GetJSONAssignment(...) (interface{}, error)
177+
GetJSONBytesAssignment(...) ([]byte, error)
147178
```
148179

149180
<br />

0 commit comments

Comments
 (0)