open-feature / open-feature/go-sdk

Make EvaluationContext optional when evaluating flags

Open
#465 10 comments 0 reactions 0 assignees View on GitHub
enhancement v2
Dominant language
Go
Stars
249
Forks
61
Avg merge
2d 10h
Merged PRs (30d)
20

Description

### Requirements

EvaluationContexts can be defined globally, on the client, on the Go context, or at the point of flag evaluation. Currently, the flag evaluation functions in the Go SDK require an `EvaluationContext`, even if there is already one defined at a higher level.

```go
// Attach an EvaluationContext globally
openfeature.SetEvaluationContext(openfeature.NewEvaluationContext(
"",
map[string]interface{}{
"myGlobalKey": "myGlobalValue",
},
))

// Attach an EvaluationContext to the client
client := openfeature.NewClient("my-app")
client.SetEvaluationContext(openfeature.NewEvaluationContext(
"",
map[string]interface{}{
"myGlobalKey": "myGlobalValue",
},
))

// Attach an EvaluationContext to the Go context
ctx := openfeature.WithTransactionContext(context.TODO(), openfeature.EvaluationContext{})

// You still need to pass an evaluation context here, even though we already attached
// evaluation contexts globally, on the client, and on the Go context.
client.Boolean(ctx, "boolFlag", false, openfeature.EvaluationContext{})
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.