open-feature / open-feature/go-sdk
Make EvaluationContext optional when evaluating flags
- 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
Assessment
This issue has not been assessed yet.