|
13 | 13 | [](https://cloud-native.slack.com/archives/C0344AANLA1)
|
14 | 14 | [](https://goreportcard.com/report/github.com/open-feature/go-sdk)
|
15 | 15 | [](https://codecov.io/gh/open-feature/go-sdk)
|
16 |
| -[](https://github.com/open-feature/spec/tree/v0.5.1) |
| 16 | +[](https://github.com/open-feature/spec/tree/v0.6.0) |
17 | 17 | [](https://bestpractices.coreinfrastructure.org/projects/6601)
|
18 | 18 |
|
19 | 19 | ## 👋 Hey there! Thanks for checking out the OpenFeature Go SDK
|
@@ -46,6 +46,7 @@ The release workflow generates an SBOM (using [cyclonedx](https://github.com/Cyc
|
46 | 46 | - easy integration and extension via [hooks](https://openfeature.dev/docs/reference/concepts/hooks)
|
47 | 47 | - bool, string, numeric, and object flag types
|
48 | 48 | - [context-aware](https://openfeature.dev/docs/reference/concepts/evaluation-context) evaluation
|
| 49 | +- Supports [OpenFeature Events](https://openfeature.dev/specification/sections/events) |
49 | 50 |
|
50 | 51 | ## 🚀 Usage:
|
51 | 52 |
|
@@ -201,6 +202,71 @@ c := openfeature.NewClient("log").WithLogger(l) // set the logger at client leve
|
201 | 202 | [logr](https://github.com/go-logr/logr) uses incremental verbosity levels (akin to named levels but in integer form).
|
202 | 203 | The SDK logs `info` at level `0` and `debug` at level `1`. Errors are always logged.
|
203 | 204 |
|
| 205 | +### Named clients: |
| 206 | + |
| 207 | +Clients can be given a name. A name is a logical identifier which can be used to associate clients with a particular provider. |
| 208 | +If a name has no associated provider, clients with that name use the global provider. |
| 209 | + |
| 210 | +```go |
| 211 | +import "github.com/open-feature/go-sdk/pkg/openfeature" |
| 212 | + |
| 213 | +... |
| 214 | + |
| 215 | +// Registering the default provider |
| 216 | +openfeature.SetProvider(NewLocalProvider()) |
| 217 | +// Registering a named provider |
| 218 | +openfeature.SetNamedProvider("clientForCache", NewCachedProvider()) |
| 219 | + |
| 220 | +// A Client backed by default provider |
| 221 | +clientWithDefault := openfeature.NewClient("") |
| 222 | +// A Client backed by NewCachedProvider |
| 223 | +clientForCache := openfeature.NewClient("clientForCache") |
| 224 | +``` |
| 225 | + |
| 226 | +### Events: |
| 227 | + |
| 228 | +Events allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions. |
| 229 | +Initialization events (PROVIDER_READY on success, PROVIDER_ERROR on failure) are dispatched for every provider. |
| 230 | +Some providers support additional events, such as PROVIDER_CONFIGURATION_CHANGED. |
| 231 | + |
| 232 | +Please refer to the documentation of the provider you're using to see what events are supported. |
| 233 | + |
| 234 | +```go |
| 235 | +import "github.com/open-feature/go-sdk/pkg/openfeature" |
| 236 | + |
| 237 | +... |
| 238 | +var readyHandlerCallback = func(details openfeature.EventDetails) { |
| 239 | + // callback implementation |
| 240 | +} |
| 241 | + |
| 242 | +// Global event handler |
| 243 | +openfeature.AddHandler(openfeature.ProviderReady, &readyHandlerCallback) |
| 244 | + |
| 245 | +... |
| 246 | + |
| 247 | +var providerErrorCallback = func(details openfeature.EventDetails) { |
| 248 | + // callback implementation |
| 249 | +} |
| 250 | + |
| 251 | +client := openfeature.NewClient("clientName") |
| 252 | + |
| 253 | +// Client event handler |
| 254 | +client.AddHandler(openfeature.ProviderError, &providerErrorCallback) |
| 255 | +``` |
| 256 | + |
| 257 | +### Shutdown: |
| 258 | + |
| 259 | +The OpenFeature API provides a close function to perform a cleanup of all registered providers. |
| 260 | +This should only be called when your application is in the process of shutting down. |
| 261 | + |
| 262 | +```go |
| 263 | +import "github.com/open-feature/go-sdk/pkg/openfeature" |
| 264 | + |
| 265 | +... |
| 266 | + |
| 267 | +openfeature.Shutdown() |
| 268 | +``` |
| 269 | + |
204 | 270 | ## ⭐️ Support the project
|
205 | 271 |
|
206 | 272 | - Give this repo a ⭐️!
|
|
0 commit comments