isolated

package
v1.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package isolated provides a factory for creating OpenFeature API instances with state independent of the global singleton.

Use isolated instances when you need DI, multi-tenancy, or test isolation.

Experimental.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAPI

func NewAPI() *openfeature.EvaluationAPI

NewAPI returns a new, independent openfeature.EvaluationAPI.

Experimental.

Example
package main

import (
	"context"
	"fmt"

	"github.com/open-feature/go-sdk/openfeature"
	"github.com/open-feature/go-sdk/openfeature/isolated"
)

func main() {
	ctx := context.Background()

	// Create an isolated API instance independent of the global singleton.
	api := isolated.NewAPI()
	defer func() { _ = api.Shutdown(ctx) }()

	// Set a default provider (waits for initialization).
	if err := api.SetProviderAndWait(ctx, openfeature.NoopProvider{}); err != nil {
		fmt.Println("SetProviderAndWait failed:", err)
		return
	}

	// Set a domain-scoped provider with WithDomain.
	if err := api.SetProviderAndWait(ctx, openfeature.NoopProvider{}, openfeature.WithDomain("my-domain")); err != nil {
		fmt.Println("SetProviderAndWait + WithDomain failed:", err)
		return
	}

	// Obtain a client bound to the domain-scoped provider.
	client := api.NewClient(openfeature.WithDomain("my-domain"))

	// Evaluate a boolean flag.
	value := client.Boolean(ctx, "my-flag", true, openfeature.EvaluationContext{})
	fmt.Printf("flag value: %v", value)
}
Output:
flag value: true

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL