Documentation
¶
Overview ¶
Package openfeatureclient implements dynamicconfig.Client on top of OpenFeature. Its YAML-decodable Config type lives in the common/dynamicconfig/openfeatureclient/config subpackage instead of here, specifically so that common/config (which embeds that Config type) doesn't transitively import github.com/open-feature/go-sdk/openfeature: that SDK starts a background goroutine (its event executor) unconditionally from its own package init(), the moment anything imports it - not only when a provider is actually configured. common/config is imported by nearly every binary and test package in this repo, so if it pulled in the OpenFeature SDK, that goroutine would exist in every one of them, permanently, and break any test using goleak.VerifyNone. Only dynamicconfigfx.New (which backs an actual running server) should import this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeregisterProvider ¶
func DeregisterProvider()
DeregisterProvider marks one previously-RegisterProvider-attached service as stopped, calling openfeature.Shutdown() once every attached service in this process has done so. Meant to be called from the matching fx.Hook's OnStop - fx only calls a hook's OnStop if its own OnStart succeeded, so this can't be called without a preceding successful RegisterProvider.
func NewOpenFeatureClient ¶
func NewOpenFeatureClient(logger log.Logger) dynamicconfig.Client
NewOpenFeatureClient creates a dynamicconfig.Client backed by OpenFeature. The returned client is usable immediately - it wraps openfeature.NewDefaultClient(), which evaluates against whatever provider is live at call time and falls back to OpenFeature's own no-op default provider until one is registered via RegisterProvider.
func RegisterProvider ¶
func RegisterProvider(ctx context.Context, providerName string, providerConfig openfeatureprovider.Decoder) error
RegisterProvider registers providerName's OpenFeature provider (looked up via openfeatureprovider.Get - see that package's doc for the plugin convention) as the process-wide default provider, at most once per process: every call after the first successful one just verifies providerName matches what's already registered and attaches to it. providerConfig is the provider plugin's own config, decoded lazily so this package never depends on any provider-specific config type.
This does blocking work (openfeature.SetProviderWithContextAndWait, which blocks on the provider's own readiness) and so is meant to be called from an fx.Hook's OnStart (see dynamicconfigfx.New), matching how other blocking/validating work in this codebase is deferred to fx.StartHook (common/config/fx.go's cfg.validate) rather than run eagerly inside an fx.Provide constructor. ctx should be the OnStart context fx provides, which carries fx's own start timeout - without it, a provider that never becomes ready (e.g. an unreachable Unleash server) would block fx.App.Start() forever instead of failing after that timeout. A returned error should fail the caller's fx.App.Start().
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package config holds only the YAML-decodable Config for the OpenFeature-backed dynamicconfig.Client, so common/config can embed it directly.
|
Package config holds only the YAML-decodable Config for the OpenFeature-backed dynamicconfig.Client, so common/config can embed it directly. |