Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ In your `go.mod`, add the SDK package as a dependency:

```
require (
github.com/Eppo-exp/golang-sdk/v3
github.com/Eppo-exp/golang-sdk/v4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📈

)
```

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

```
go get github.com/Eppo-exp/golang-sdk/v3
go get github.com/Eppo-exp/golang-sdk/v4
```

## Quick start
Expand All @@ -40,7 +40,7 @@ Begin by initializing a singleton instance of Eppo's client. Once initialized, t

```go
import (
"github.com/Eppo-exp/golang-sdk/v3/eppoclient"
"github.com/Eppo-exp/golang-sdk/v4/eppoclient"
)

var eppoClient = &eppoclient.EppoClient{}
Expand All @@ -60,16 +60,16 @@ func main() {

```go
import (
"github.com/Eppo-exp/golang-sdk/v3/eppoclient"
"github.com/Eppo-exp/golang-sdk/v4/eppoclient"
)

var eppoClient = &eppoclient.EppoClient{}

variation := eppoClient.GetStringAssignment(
"new-user-onboarding",
user.id,
'new-user-onboarding',
user.attributes,
'control'
"control"
);
```

Expand All @@ -89,8 +89,8 @@ Each function has the same signature, but returns the type in the function name.

```go
func getBooleanAssignment(
subjectKey string,
flagKey string,
subjectKey string,
subjectAttributes SubjectAttributes,
defaultValue string
) bool
Expand All @@ -105,7 +105,7 @@ The code below illustrates an example implementation of a logging callback using

```go
import (
"github.com/Eppo-exp/golang-sdk/v2/eppoclient"
"github.com/Eppo-exp/golang-sdk/v4/eppoclient"
"gopkg.in/segmentio/analytics-go.v3"
)

Expand Down
22 changes: 11 additions & 11 deletions eppoclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func newEppoClient(configRequestor iConfigRequestor, poller *poller, assignmentL
return ec
}

func (ec *EppoClient) GetBoolAssignment(subjectKey string, flagKey string, subjectAttributes SubjectAttributes, defaultValue bool) (bool, error) {
variation, err := ec.getAssignment(subjectKey, flagKey, subjectAttributes, booleanVariation)
func (ec *EppoClient) GetBoolAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue bool) (bool, error) {
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, booleanVariation)
if err != nil || variation == nil {
return defaultValue, err
}
Expand All @@ -36,8 +36,8 @@ func (ec *EppoClient) GetBoolAssignment(subjectKey string, flagKey string, subje
return result, err
}

func (ec *EppoClient) GetNumericAssignment(subjectKey string, flagKey string, subjectAttributes SubjectAttributes, defaultValue float64) (float64, error) {
variation, err := ec.getAssignment(subjectKey, flagKey, subjectAttributes, numericVariation)
func (ec *EppoClient) GetNumericAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue float64) (float64, error) {
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, numericVariation)
if err != nil || variation == nil {
return defaultValue, err
}
Expand All @@ -48,8 +48,8 @@ func (ec *EppoClient) GetNumericAssignment(subjectKey string, flagKey string, su
return result, err
}

func (ec *EppoClient) GetIntegerAssignment(subjectKey string, flagKey string, subjectAttributes SubjectAttributes, defaultValue int64) (int64, error) {
variation, err := ec.getAssignment(subjectKey, flagKey, subjectAttributes, integerVariation)
func (ec *EppoClient) GetIntegerAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue int64) (int64, error) {
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, integerVariation)
if err != nil || variation == nil {
return defaultValue, err
}
Expand All @@ -60,8 +60,8 @@ func (ec *EppoClient) GetIntegerAssignment(subjectKey string, flagKey string, su
return result, err
}

func (ec *EppoClient) GetStringAssignment(subjectKey string, flagKey string, subjectAttributes SubjectAttributes, defaultValue string) (string, error) {
variation, err := ec.getAssignment(subjectKey, flagKey, subjectAttributes, stringVariation)
func (ec *EppoClient) GetStringAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue string) (string, error) {
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, stringVariation)
if err != nil || variation == nil {
return defaultValue, err
}
Expand All @@ -72,15 +72,15 @@ func (ec *EppoClient) GetStringAssignment(subjectKey string, flagKey string, sub
return result, err
}

func (ec *EppoClient) GetJSONAssignment(subjectKey string, flagKey string, subjectAttributes SubjectAttributes, defaultValue interface{}) (interface{}, error) {
variation, err := ec.getAssignment(subjectKey, flagKey, subjectAttributes, jsonVariation)
func (ec *EppoClient) GetJSONAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue interface{}) (interface{}, error) {
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, jsonVariation)
if err != nil || variation == nil {
return defaultValue, err
}
return variation, err
}

func (ec *EppoClient) getAssignment(subjectKey string, flagKey string, subjectAttributes SubjectAttributes, variationType variationType) (interface{}, error) {
func (ec *EppoClient) getAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, variationType variationType) (interface{}, error) {
if subjectKey == "" {
panic("no subject key provided")
}
Expand Down
8 changes: 4 additions & 4 deletions eppoclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Test_AssignBlankExperiment(t *testing.T) {
client := newEppoClient(mockConfigRequestor, poller, mockLogger)

assert.Panics(t, func() {
_, err := client.GetStringAssignment("subject-1", "", SubjectAttributes{}, "")
_, err := client.GetStringAssignment("", "subject-1", SubjectAttributes{}, "")
if err != nil {
log.Println(err)
}
Expand All @@ -29,7 +29,7 @@ func Test_AssignBlankSubject(t *testing.T) {
client := newEppoClient(mockConfigRequestor, poller, mockLogger)

assert.Panics(t, func() {
_, err := client.GetStringAssignment("", "experiment-1", SubjectAttributes{}, "")
_, err := client.GetStringAssignment("experiment-1", "", SubjectAttributes{}, "")
if err != nil {
log.Println(err)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func Test_LogAssignment(t *testing.T) {

client := newEppoClient(mockConfigRequestor, poller, mockLogger)

assignment, err := client.GetStringAssignment("user-1", "experiment-key-1", SubjectAttributes{}, "")
assignment, err := client.GetStringAssignment("experiment-key-1", "user-1",SubjectAttributes{}, "")
expected := "control"

assert.Nil(t, err)
Expand Down Expand Up @@ -136,7 +136,7 @@ func Test_GetStringAssignmentHandlesLoggingPanic(t *testing.T) {

client := newEppoClient(mockConfigRequestor, poller, mockLogger)

assignment, err := client.GetStringAssignment("user-1", "experiment-key-1", SubjectAttributes{}, "")
assignment, err := client.GetStringAssignment("experiment-key-1", "user-1", SubjectAttributes{}, "")
expected := "control"

assert.Nil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions eppoclient/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Usage:

import (
"github.com/Eppo-exp/golang-sdk/v2/eppoclient"
"github.com/Eppo-exp/golang-sdk/v4/eppoclient"
)

var eppoClient = &eppoclient.EppoClient{}
Expand All @@ -18,7 +18,7 @@
}

func apiEndpoint() {
assignment, _ := eppoClient.GetStringAssignment("subject-1", "experiment_5", sbjAttrs)
assignment, _ := eppoClient.GetStringAssignment("experiment_5", "subject-1", sbjAttrs, "control")

if assignment == "control" {
// do something
Expand Down
10 changes: 5 additions & 5 deletions eppoclient/eppoclient_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ func Test_e2e(t *testing.T) {
t.Run(subject.SubjectKey, func(t *testing.T) {
switch test.VariationType {
case booleanVariation:
value, _ := client.GetBoolAssignment(subject.SubjectKey, test.Flag, subject.SubjectAttributes, test.DefaultValue.(bool))
value, _ := client.GetBoolAssignment(test.Flag, subject.SubjectKey, subject.SubjectAttributes, test.DefaultValue.(bool))
assert.Equal(t, subject.Assignment, value)
case numericVariation:
value, _ := client.GetNumericAssignment(subject.SubjectKey, test.Flag, subject.SubjectAttributes, test.DefaultValue.(float64))
value, _ := client.GetNumericAssignment(test.Flag, subject.SubjectKey, subject.SubjectAttributes, test.DefaultValue.(float64))
assert.Equal(t, subject.Assignment, value)
case integerVariation:
value, _ := client.GetIntegerAssignment(subject.SubjectKey, test.Flag, subject.SubjectAttributes, int64(test.DefaultValue.(float64)))
value, _ := client.GetIntegerAssignment(test.Flag, subject.SubjectKey, subject.SubjectAttributes, int64(test.DefaultValue.(float64)))
assert.Equal(t, int64(subject.Assignment.(float64)), value)

case jsonVariation:
value, _ := client.GetJSONAssignment(subject.SubjectKey, test.Flag, subject.SubjectAttributes, test.DefaultValue)
value, _ := client.GetJSONAssignment(test.Flag, subject.SubjectKey, subject.SubjectAttributes, test.DefaultValue)
assert.Equal(t, subject.Assignment, value)
case stringVariation:
value, _ := client.GetStringAssignment(subject.SubjectKey, test.Flag, subject.SubjectAttributes, test.DefaultValue.(string))
value, _ := client.GetStringAssignment(test.Flag, subject.SubjectKey, subject.SubjectAttributes, test.DefaultValue.(string))
assert.Equal(t, subject.Assignment, value)
default:
panic(fmt.Sprintf("unknown variation: %v", test.VariationType))
Expand Down
2 changes: 1 addition & 1 deletion eppoclient/initclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package eppoclient

import "net/http"

var __version__ = "3.0.0"
var __version__ = "4.0.0"

// InitClient is required to start polling of experiments configurations and create
// an instance of EppoClient, which could be used to get assignments information.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Eppo-exp/golang-sdk/v3
module github.com/Eppo-exp/golang-sdk/v4

go 1.19

Expand Down