Skip to content

Commit 1d70cb2

Browse files
chore: adding state and eventing to readme (#198)
* state and eventing readme Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com> * readme update Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com> * review - update description Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com> --------- Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
1 parent 940cb8b commit 1d70cb2

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[![a](https://img.shields.io/badge/slack-%40cncf%2Fopenfeature-brightgreen?style=flat&logo=slack)](https://cloud-native.slack.com/archives/C0344AANLA1)
1414
[![Go Report Card](https://goreportcard.com/badge/github.com/open-feature/go-sdk)](https://goreportcard.com/report/github.com/open-feature/go-sdk)
1515
[![codecov](https://codecov.io/gh/open-feature/go-sdk/branch/main/graph/badge.svg?token=FZ17BHNSU5)](https://codecov.io/gh/open-feature/go-sdk)
16-
[![v0.5.1](https://img.shields.io/static/v1?label=Specification&message=v0.5.1&color=yellow)](https://github.com/open-feature/spec/tree/v0.5.1)
16+
[![v0.6.0](https://img.shields.io/static/v1?label=Specification&message=v0.6.0&color=yellow)](https://github.com/open-feature/spec/tree/v0.6.0)
1717
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6601/badge)](https://bestpractices.coreinfrastructure.org/projects/6601)
1818

1919
## 👋 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
4646
- easy integration and extension via [hooks](https://openfeature.dev/docs/reference/concepts/hooks)
4747
- bool, string, numeric, and object flag types
4848
- [context-aware](https://openfeature.dev/docs/reference/concepts/evaluation-context) evaluation
49+
- Supports [OpenFeature Events](https://openfeature.dev/specification/sections/events)
4950

5051
## 🚀 Usage:
5152

@@ -201,6 +202,71 @@ c := openfeature.NewClient("log").WithLogger(l) // set the logger at client leve
201202
[logr](https://github.com/go-logr/logr) uses incremental verbosity levels (akin to named levels but in integer form).
202203
The SDK logs `info` at level `0` and `debug` at level `1`. Errors are always logged.
203204

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+
204270
## ⭐️ Support the project
205271

206272
- Give this repo a ⭐️!

0 commit comments

Comments
 (0)