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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ Load validation data separately, useful for complex applications:

```go
prepared := client.GetSwitcher("").
CheckValue("USER_123")
Check(client.StrategyValue, "USER_123")

if err := prepared.Prepare("USER_FEATURE"); err != nil {
panic(err)
Expand All @@ -321,8 +321,12 @@ Chain multiple validation strategies for comprehensive feature control:
```go
isEnabled, err := client.GetSwitcher("PREMIUM_FEATURES").
CheckValue("premium_user").
CheckNumeric("42").
CheckDate("2026-06-24").
CheckTime("09:30").
CheckPayload(`{"tier":"premium","account":{"region":"us"}}`).
CheckNetwork("192.168.1.0/24").
DefaultResult(true).
CheckRegex(`premium_[a-z]+`).
Throttle(time.Second).
IsOn()

Expand All @@ -335,6 +339,9 @@ if isEnabled {
}
```

Supported convenience helpers map to the same generic entry-point: `CheckValue`, `CheckNumeric`,
`CheckDate`, `CheckTime`, `CheckPayload`, `CheckNetwork`, and `CheckRegex`.

### Error Handling

Subscribe to error notifications for robust error management:
Expand Down
30 changes: 30 additions & 0 deletions execution_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,36 @@ func TestExecutionLogger(t *testing.T) {
assert.Equal(t, ExecutionEntry{}, logged)
})

t.Run("should log generic strategy checks and retrieve them by switcher", func(t *testing.T) {
server := newRemoteTestServer(t, remoteTestHandlers{
authStatus: http.StatusOK,
authBody: map[string]any{"token": "[token]", "exp": time.Now().Add(time.Hour).Unix()},
criteriaStatus: http.StatusOK,
criteriaBody: map[string]any{"result": true},
})
defer server.Close()

client := NewClient(Context{
Domain: "My Domain",
URL: server.URL,
APIKey: "[YOUR_API_KEY]",
Component: "MyApp",
Options: ContextOptions{
Logger: true,
},
})

got, err := client.GetSwitcher("MY_SWITCHER").Check(StrategyRegex, "USER_11").IsOn()

assert.NoError(t, err)
assert.True(t, got)

logged := client.GetExecution(client.GetSwitcher("MY_SWITCHER").Check(StrategyRegex, "USER_11"))
assert.Equal(t, "MY_SWITCHER", logged.Key)
assert.Equal(t, []ExecutionInput{{Strategy: StrategyRegex, Input: "USER_11"}}, logged.Inputs)
assert.True(t, logged.Response.Result)
})

t.Run("should return empty execution when the logged entry has inputs and the lookup has none", func(t *testing.T) {
server := newRemoteTestServer(t, remoteTestHandlers{
authStatus: http.StatusOK,
Expand Down
Loading