Documentation
¶
Overview ¶
Package featureflip provides an OpenFeature provider backed by the Featureflip Go server SDK.
Register it with the OpenFeature API and evaluate flags through the standard client:
provider := featureflip.NewProvider("sdk-xxx")
if err := openfeature.SetProviderAndWait(provider); err != nil {
log.Fatal(err)
}
client := openfeature.NewClient("my-app")
enabled := client.Boolean(ctx, "new-checkout", false, openfeature.NewEvaluationContext(
"user-123", map[string]any{"plan": "pro"},
))
Use SetProviderAndWait rather than SetProvider: the plain form runs Init on a background goroutine and returns before the first flag load has finished, so evaluations on the following lines can hand back their defaults.
If you also import the Featureflip SDK directly, alias one of the two — both packages are named featureflip:
import ( sdk "github.com/canopy-labs/featureflip-go/v2" featureflip "github.com/canopy-labs/featureflip-go-openfeature" )
Index ¶
- Constants
- type Provider
- func (p *Provider) BooleanEvaluation(_ context.Context, flag string, defaultValue bool, ...) openfeature.BoolResolutionDetail
- func (p *Provider) EventChannel() <-chan openfeature.Event
- func (p *Provider) FloatEvaluation(_ context.Context, flag string, defaultValue float64, ...) openfeature.FloatResolutionDetail
- func (p *Provider) Hooks() []openfeature.Hook
- func (p *Provider) Init(_ openfeature.EvaluationContext) error
- func (p *Provider) IntEvaluation(_ context.Context, flag string, defaultValue int64, ...) openfeature.IntResolutionDetail
- func (p *Provider) Metadata() openfeature.Metadata
- func (p *Provider) ObjectEvaluation(_ context.Context, flag string, defaultValue any, ...) openfeature.InterfaceResolutionDetail
- func (p *Provider) Shutdown()
- func (p *Provider) StringEvaluation(_ context.Context, flag string, defaultValue string, ...) openfeature.StringResolutionDetail
- func (p *Provider) Track(_ context.Context, trackingEventName string, ...)
Constants ¶
const PrerequisiteFailedReason openfeature.Reason = "PREREQUISITE_FAILED"
PrerequisiteFailedReason is returned when a flag short-circuited because one of its prerequisites did not serve its expected variation.
No standard OpenFeature reason models an unmet prerequisite. Reasons are open strings, so this surfaces it verbatim rather than mislabelling it as DEFAULT or DISABLED — the same choice the Node, .NET and Python providers made.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is an OpenFeature provider backed by the Featureflip Go server SDK.
Construct it either with an SDK key, in which case the provider creates and owns the underlying client, or with an existing client, in which case the caller keeps ownership and Shutdown leaves it open.
A Provider is safe for concurrent use.
func NewProvider ¶
NewProvider returns a provider that owns its client.
The client is constructed in Init, not here, because construction blocks on the initial flag fetch. Building it in the constructor would move that wait out of SetProviderAndWait, where callers expect it.
If sdkKey is empty the SDK falls back to the FEATUREFLIP_SDK_KEY environment variable, and Init reports an error if neither is set.
func NewProviderWithClient ¶
NewProviderWithClient returns a provider backed by an existing client.
The caller retains ownership: Shutdown will not close it. Use this when the same process also evaluates flags through the SDK directly, so that both paths share one client rather than opening a second stream.
func (*Provider) BooleanEvaluation ¶
func (p *Provider) BooleanEvaluation( _ context.Context, flag string, defaultValue bool, flatCtx openfeature.FlattenedContext, ) openfeature.BoolResolutionDetail
BooleanEvaluation resolves a boolean flag.
func (*Provider) EventChannel ¶ added in v0.2.0
func (p *Provider) EventChannel() <-chan openfeature.Event
EventChannel exposes this provider's event stream to the OpenFeature SDK.
The channel is never closed. The SDK's reader treats a close as "stop listening", but closing it here would race any listener still in flight and panic on a send to a closed channel; the SDK exits that goroutine on its own shutdown signal instead.
func (*Provider) FloatEvaluation ¶
func (p *Provider) FloatEvaluation( _ context.Context, flag string, defaultValue float64, flatCtx openfeature.FlattenedContext, ) openfeature.FloatResolutionDetail
FloatEvaluation resolves a float flag.
func (*Provider) Hooks ¶
func (p *Provider) Hooks() []openfeature.Hook
Hooks returns no provider hooks; Featureflip has nothing to add here.
func (*Provider) Init ¶
func (p *Provider) Init(_ openfeature.EvaluationContext) error
Init constructs the client if this provider owns one.
The evaluation context is unused: Featureflip is a dynamic-context (server) provider, so targeting comes from the per-evaluation context rather than being bound at initialization.
It is safe to call more than once; OpenFeature may re-initialize a provider that is already initialized.
func (*Provider) IntEvaluation ¶
func (p *Provider) IntEvaluation( _ context.Context, flag string, defaultValue int64, flatCtx openfeature.FlattenedContext, ) openfeature.IntResolutionDetail
IntEvaluation resolves an integer flag.
func (*Provider) Metadata ¶
func (p *Provider) Metadata() openfeature.Metadata
Metadata identifies this provider to the OpenFeature SDK.
func (*Provider) ObjectEvaluation ¶
func (p *Provider) ObjectEvaluation( _ context.Context, flag string, defaultValue any, flatCtx openfeature.FlattenedContext, ) openfeature.InterfaceResolutionDetail
ObjectEvaluation resolves an object or array flag.
func (*Provider) Shutdown ¶
func (p *Provider) Shutdown()
Shutdown closes the client only if this provider created it.
A caller-supplied client is a refcounted handle the caller still holds; closing it would make THEIR handle start returning defaults.
func (*Provider) StringEvaluation ¶
func (p *Provider) StringEvaluation( _ context.Context, flag string, defaultValue string, flatCtx openfeature.FlattenedContext, ) openfeature.StringResolutionDetail
StringEvaluation resolves a string flag.
func (*Provider) Track ¶
func (p *Provider) Track( _ context.Context, trackingEventName string, evaluationContext openfeature.EvaluationContext, details openfeature.TrackingEventDetails, )
Track records a custom analytics event against the Featureflip client.