Skip to content

Commit e687a38

Browse files
authored
Feature/assignment logger interface (#13)
* Add README so that package info on pkg.go.dev will be shown more nicely * Change logAssignment func to accept AssignmentEvent * Fix * Fix for readme * Linter fix
1 parent 1732d6b commit e687a38

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It is used to retrieve the experiments data and put it to in-memory cache, and t
77

88
Refer to our [SDK documentation](https://docs.geteppo.com/prerequisites/feature-flagging/randomization-sdk/) for how to install and use the SDK.
99

10-
## Supported Python Versions
10+
## Supported Go Versions
1111
This version of the SDK is compatible with Go v1.18 and above.
1212

1313
## Example

eppoclient/assignmentlogger.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ package eppoclient
33
import "fmt"
44

55
type IAssignmentLogger interface {
6-
LogAssignment(event map[string]string)
6+
LogAssignment(event AssignmentEvent)
7+
}
8+
9+
type AssignmentEvent struct {
10+
Experiment string
11+
Variation string
12+
Subject string
13+
Timestamp string
14+
SubjectAttributes dictionary
715
}
816

917
type AssignmentLogger struct {
@@ -13,7 +21,7 @@ func NewAssignmentLogger() IAssignmentLogger {
1321
return &AssignmentLogger{}
1422
}
1523

16-
func (al *AssignmentLogger) LogAssignment(event map[string]string) {
24+
func (al *AssignmentLogger) LogAssignment(event AssignmentEvent) {
1725
fmt.Println("Assignment Logged")
1826
fmt.Println(event)
1927
}

eppoclient/client.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ type EppoClient struct {
1717
logger IAssignmentLogger
1818
}
1919

20-
type assignmentEvent struct {
21-
Experiment string
22-
Variation string
23-
Subject string
24-
Timestamp string
25-
SubjectAttributes dictionary
26-
}
27-
2820
func newEppoClient(configRequestor iConfigRequestor, assignmentLogger IAssignmentLogger) *EppoClient {
2921
var ec = &EppoClient{}
3022

@@ -75,15 +67,19 @@ func (ec *EppoClient) GetAssignment(subjectKey string, experimentKey string, sub
7567

7668
assignedVariation := variationShard.Name
7769

78-
assignmentEvent := &assignmentEvent{
70+
assignmentEvent := AssignmentEvent{
7971
Experiment: experimentKey,
8072
Variation: assignedVariation,
8173
Subject: subjectKey,
8274
Timestamp: time.Now().String(),
8375
SubjectAttributes: subjectAttributes,
8476
}
8577

86-
aeJson, _ := json.Marshal(assignmentEvent)
78+
_, jsonErr := json.Marshal(assignmentEvent)
79+
80+
if jsonErr != nil {
81+
panic("incorrect json")
82+
}
8783

8884
func() {
8985
// need to catch panics from Logger and continue
@@ -94,10 +90,7 @@ func (ec *EppoClient) GetAssignment(subjectKey string, experimentKey string, sub
9490
}
9591
}()
9692

97-
event := map[string]string{}
98-
json.Unmarshal([]byte(aeJson), &event)
99-
100-
ec.logger.LogAssignment(event)
93+
ec.logger.LogAssignment(assignmentEvent)
10194
}()
10295

10396
return assignedVariation, nil

eppoclient/mocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type mockLogger struct {
88
mock.Mock
99
}
1010

11-
func (ml *mockLogger) LogAssignment(event map[string]string) {
11+
func (ml *mockLogger) LogAssignment(event AssignmentEvent) {
1212
ml.Called(event)
1313
}
1414

0 commit comments

Comments
 (0)