Documentation
¶
Overview ¶
Package openfeature adapts an OpenFeature provider to the phpboyscout Go toolkit's feature core: a features.Backend over any openfeature.FeatureProvider, so one adapter opens every vendor that speaks OpenFeature (LaunchDarkly, Unleash and therefore GitLab Feature Flags, flagd, and the rest).
It works at the provider level rather than through the SDK's client, so it touches no global (the SDK's singleton API is never set), carries no hooks and is about three times cheaper per evaluation (go-tool-base spec 0199's spike measured 322 ns against 940 ns). The provider's optional lifecycle and event interfaces map onto Backend's: StateHandler or ContextAwareStateHandler onto Init and Close, EventHandler onto Watch and Ready.
Index ¶
- type Backend
- func (b *Backend) Close() error
- func (b *Backend) Init(ctx context.Context) error
- func (b *Backend) Ready() bool
- func (b *Backend) Resolve(ctx context.Context, id features.ID, fallback bool, ec features.EvalContext) (features.Decision, error)
- func (b *Backend) Watch(context.Context) <-chan features.Change
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is a features.Backend over an OpenFeature provider.
func New ¶
func New(provider openfeature.FeatureProvider, opts ...Option) *Backend
New wraps provider as a features.Backend.
func (*Backend) Close ¶
Close stops the event forwarder and shuts the provider down through whichever state handler it offers.
func (*Backend) Init ¶
Init initialises the provider through whichever state handler it offers (the context-aware one first), then starts forwarding its events when it has any. A provider with no state handler is ready at once.
func (*Backend) Ready ¶
Ready reports whether Init has succeeded and the provider has not since reported itself stale or errored.
func (*Backend) Resolve ¶
func (b *Backend) Resolve(ctx context.Context, id features.ID, fallback bool, ec features.EvalContext) (features.Decision, error)
Resolve asks the provider for a boolean evaluation with the caller's static state as the default value. OpenFeature returns that default for an unknown flag (with FLAG_NOT_FOUND) and for a disabled one (reason DISABLED); the disabled case is a clean answer here, whatever error a provider attaches to it, because the fallback applying is exactly what disabled means.
type Option ¶
type Option func(*Backend)
Option configures a Backend.
func WithInitContext ¶
func WithInitContext(ec openfeature.EvaluationContext) Option
WithInitContext sets the OpenFeature evaluation context handed to the provider's Init: the global targeting context some vendors want up front.