openfeature

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 12 Imported by: 96

Documentation

Overview

Package openfeature provides global access to the OpenFeature API.

Index

Examples

Constants

View Source
const (
	// DefaultReason - the resolved value was configured statically, or otherwise fell back to a pre-configured value.
	DefaultReason Reason = "DEFAULT"
	// TargetingMatchReason - the resolved value was the result of a dynamic evaluation, such as a rule or specific user-targeting.
	TargetingMatchReason Reason = "TARGETING_MATCH"
	// SplitReason - the resolved value was the result of pseudorandom assignment.
	SplitReason Reason = "SPLIT"
	// DisabledReason - the resolved value was the result of the flag being disabled in the management system.
	DisabledReason Reason = "DISABLED"
	// StaticReason - the resolved value is static (no dynamic evaluation)
	StaticReason Reason = "STATIC"
	// CachedReason - the resolved value was retrieved from cache
	CachedReason Reason = "CACHED"
	// UnknownReason - the reason for the resolved value could not be determined.
	UnknownReason Reason = "UNKNOWN"
	// ErrorReason - the resolved value was the result of an error.
	ErrorReason Reason = "ERROR"

	NotReadyState State = "NOT_READY"
	ReadyState    State = "READY"
	ErrorState    State = "ERROR"
	StaleState    State = "STALE"
	FatalState    State = "FATAL"

	ProviderReady        EventType = "PROVIDER_READY"
	ProviderConfigChange EventType = "PROVIDER_CONFIGURATION_CHANGED"
	ProviderStale        EventType = "PROVIDER_STALE"
	ProviderError        EventType = "PROVIDER_ERROR"

	TargetingKey string = "targetingKey" // evaluation context map key. The targeting key uniquely identifies the subject (end-user, or client service) of a flag evaluation.
)

Variables

View Source
var (
	// ProviderNotReadyError signifies that an operation failed because the provider is in a NOT_READY state.
	ProviderNotReadyError = NewProviderNotReadyResolutionError("provider not yet initialized")
	// ProviderFatalError signifies that an operation failed because the provider is in a FATAL state.
	ProviderFatalError = NewProviderFatalResolutionError("provider is in an irrecoverable error state")
)

Functions

func AddHandler

func AddHandler(eventType EventType, callback EventCallback)

AddHandler allows to add API level event handlers

func AddHooks

func AddHooks(hooks ...Hook)

AddHooks appends to the collection of any previously added hooks

func MergeTransactionContext added in v1.13.0

func MergeTransactionContext(ctx context.Context, ec EvaluationContext) context.Context

MergeTransactionContext merges the provided EvaluationContext with the current TransactionContext (if it exists)

ctx - the context to pull existing TransactionContext from ec - the EvaluationContext to merge with the existing TransactionContext

func RemoveHandler

func RemoveHandler(eventType EventType, callback EventCallback)

RemoveHandler allows for removal of API level event handlers

func SetEvaluationContext

func SetEvaluationContext(evalCtx EvaluationContext)

SetEvaluationContext sets the global EvaluationContext.

func SetLogger deprecated

func SetLogger(l logr.Logger)

SetLogger sets the global Logger.

Deprecated: use github.com/open-feature/go-sdk/openfeature/hooks.LoggingHook instead.

func SetNamedProvider

func SetNamedProvider(domain string, provider FeatureProvider) error

SetNamedProvider sets a FeatureProvider mapped to the given Client domain. Provider initialization is asynchronous and status can be checked from provider status

func SetNamedProviderAndWait added in v1.10.0

func SetNamedProviderAndWait(domain string, provider FeatureProvider) error

SetNamedProviderAndWait sets a provider mapped to the given Client domain and waits for its initialization. Returns an error if initialization cause error

func SetNamedProviderWithContext added in v1.17.0

func SetNamedProviderWithContext(ctx context.Context, domain string, provider FeatureProvider) error

SetNamedProviderWithContext sets a FeatureProvider mapped to the given Client domain with context-aware initialization. If the provider implements ContextAwareStateHandler, InitWithContext will be called with the provided context. Provider initialization is asynchronous and status can be checked from provider status. Returns an error immediately if provider is nil, or if context is cancelled during setup.

Named providers allow different domains to use different feature flag providers, enabling multi-tenant applications or microservice architectures.

Example

ExampleSetNamedProviderWithContext demonstrates multi-tenant provider setup.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

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

func main() {
	// Create test providers for different services
	userProvider := &openfeature.NoopProvider{}
	billingProvider := &openfeature.NoopProvider{}

	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
	defer cancel()

	err := openfeature.SetNamedProviderWithContext(ctx, "user-service", userProvider)
	if err != nil {
		log.Printf("Failed to setup user service provider: %v", err)
		return
	}

	err = openfeature.SetNamedProviderWithContext(ctx, "billing-service", billingProvider)
	if err != nil {
		log.Printf("Failed to setup billing service provider: %v", err)
		return
	}

	// Create clients for different domains
	userClient := openfeature.NewClient("user-service")
	billingClient := openfeature.NewClient("billing-service")

	fmt.Printf("User client domain: %s\n", userClient.Metadata().Domain())
	fmt.Printf("Billing client domain: %s\n", billingClient.Metadata().Domain())
}
Output:

User client domain: user-service
Billing client domain: billing-service

func SetNamedProviderWithContextAndWait added in v1.17.0

func SetNamedProviderWithContextAndWait(ctx context.Context, domain string, provider FeatureProvider) error

SetNamedProviderWithContextAndWait sets a provider mapped to the given Client domain with context-aware initialization and waits for completion. If the provider implements ContextAwareStateHandler, InitWithContext will be called with the provided context. Returns an error if initialization causes an error, or if context is cancelled during initialization.

Use this for synchronous named provider setup where you need to ensure the provider is ready before proceeding.

Example

ExampleSetNamedProviderWithContextAndWait demonstrates critical service provider setup.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

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

func main() {
	// Create a test provider for demonstration
	criticalProvider := &openfeature.NoopProvider{}

	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	// Wait for critical providers to be ready
	err := openfeature.SetNamedProviderWithContextAndWait(ctx, "critical-service", criticalProvider)
	if err != nil {
		log.Printf("Critical provider failed to initialize: %v", err)
		return
	}

	// Now safe to use the client
	client := openfeature.NewClient("critical-service")
	enabled, _ := client.BooleanValue(context.Background(), "feature-x", false, openfeature.EvaluationContext{})

	fmt.Printf("Critical service ready, feature-x enabled: %v\n", enabled)
}
Output:

Critical service ready, feature-x enabled: false

func SetProvider

func SetProvider(provider FeatureProvider) error

SetProvider sets the default FeatureProvider. Provider initialization is asynchronous and status can be checked from provider status

func SetProviderAndWait added in v1.10.0

func SetProviderAndWait(provider FeatureProvider) error

SetProviderAndWait sets the default FeatureProvider and waits for its initialization. Returns an error if initialization causes an error

func SetProviderWithContext added in v1.17.0

func SetProviderWithContext(ctx context.Context, provider FeatureProvider) error

SetProviderWithContext sets the default FeatureProvider with context-aware initialization. If the provider implements ContextAwareStateHandler, InitWithContext will be called with the provided context. Provider initialization is asynchronous and status can be checked from provider status. Returns an error immediately if provider is nil, or if context is cancelled during setup.

Use this function for non-blocking provider setup with timeout control where you want to continue application startup while the provider initializes in background. For providers that don't implement ContextAwareStateHandler, this behaves identically to SetProvider() but with timeout protection.

Example

ExampleSetProviderWithContext demonstrates asynchronous provider setup with timeout control.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

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

func main() {
	// Create a test provider for demonstration
	provider := &openfeature.NoopProvider{}

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	err := openfeature.SetProviderWithContext(ctx, provider)
	if err != nil {
		log.Printf("Failed to start provider setup: %v", err)
		return
	}

	// Provider continues initializing in background
	fmt.Println("Provider setup initiated")
}
Output:

Provider setup initiated

func SetProviderWithContextAndWait added in v1.17.0

func SetProviderWithContextAndWait(ctx context.Context, provider FeatureProvider) error

SetProviderWithContextAndWait sets the default FeatureProvider with context-aware initialization and waits for completion. If the provider implements ContextAwareStateHandler, InitWithContext will be called with the provided context. Returns an error if initialization causes an error, or if context is cancelled during initialization.

Use this function for synchronous provider setup with guaranteed readiness when you need application startup to wait for the provider before continuing. Recommended timeout values: 1-5s for local providers, 10-30s for network-based providers.

Example

ExampleSetProviderWithContextAndWait demonstrates synchronous provider setup with error handling.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

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

func main() {
	// Create a test provider for demonstration
	provider := &openfeature.NoopProvider{}

	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	err := openfeature.SetProviderWithContextAndWait(ctx, provider)
	if err != nil {
		log.Printf("Provider initialization failed: %v", err)
		return
	}

	// Provider is now ready to use
	fmt.Println("Provider is ready")
}
Output:

Provider is ready

func Shutdown

func Shutdown()

Shutdown unconditionally calls shutdown on all registered providers, regardless of their state. It resets the state of the API, removing all hooks, event handlers, and providers.

func ShutdownWithContext added in v1.17.0

func ShutdownWithContext(ctx context.Context) error

ShutdownWithContext calls context-aware shutdown on all registered providers. If providers implement ContextAwareStateHandler, ShutdownWithContext will be called with the provided context. It resets the state of the API, removing all hooks, event handlers, and providers. This is intended to be called when your application is terminating. Returns an error if any provider shutdown fails or if context is cancelled during shutdown.

Example

ExampleShutdownWithContext demonstrates graceful application shutdown with timeout control.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

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

func main() {
	// Set up providers
	provider1 := &openfeature.NoopProvider{}
	provider2 := &openfeature.NoopProvider{}

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	// Set up multiple providers
	err := openfeature.SetProviderWithContextAndWait(ctx, provider1)
	if err != nil {
		log.Printf("Provider setup failed: %v", err)
		return
	}

	err = openfeature.SetNamedProviderWithContextAndWait(ctx, "service-a", provider2)
	if err != nil {
		log.Printf("Named provider setup failed: %v", err)
		return
	}

	// Application is running...

	// When application is shutting down, use context-aware shutdown
	shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer shutdownCancel()

	err = openfeature.ShutdownWithContext(shutdownCtx)
	if err != nil {
		log.Printf("Shutdown completed with errors: %v", err)
	} else {
		fmt.Println("All providers shut down successfully")
	}

}
Output:

All providers shut down successfully

func WithTransactionContext added in v1.13.0

func WithTransactionContext(ctx context.Context, ec EvaluationContext) context.Context

WithTransactionContext constructs a TransactionContext.

ctx - the context to embed the EvaluationContext in ec - the EvaluationContext to embed into the context

Types

type BoolResolutionDetail

type BoolResolutionDetail = GenericResolutionDetail[bool]

BoolResolutionDetail represents the result of the provider's flag resolution process for boolean flags.

type BooleanEvaluationDetails

type BooleanEvaluationDetails = GenericEvaluationDetails[bool]

BooleanEvaluationDetails represents the result of the flag evaluation process for boolean flags.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements the behaviour required of an openfeature client

func NewClient

func NewClient(domain string) *Client

NewClient returns a new Client. Name is a unique identifier for this client This helper exists for historical reasons. It is recommended to interact with IEvaluation to derive IClient instances.

Example
package main

import (
	"fmt"

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

func main() {
	client := openfeature.NewClient("example-client")
	fmt.Printf("Client Domain: %s", client.Metadata().Domain())
}
Output:

Client Domain: example-client

func NewDefaultClient added in v1.16.0

func NewDefaultClient() *Client

NewDefaultClient returns a Client for the default domain. The default domain Client is the IClient instance that wraps around an unnamed FeatureProvider

func (*Client) AddHandler

func (c *Client) AddHandler(eventType EventType, callback EventCallback)

AddHandler allows to add Client level event handler

func (*Client) AddHooks

func (c *Client) AddHooks(hooks ...Hook)

AddHooks appends to the client's collection of any previously added hooks

func (*Client) Boolean added in v1.11.0

func (c *Client) Boolean(ctx context.Context, flag string, defaultValue bool, evalCtx EvaluationContext, options ...Option) bool

Boolean performs a flag evaluation that returns a boolean. Any error encountered during the evaluation will result in the default value being returned. To explicitly handle errors, use Client.BooleanValue or Client.BooleanValueDetails

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	ctx := context.TODO()
	client := openfeature.NewClient("example-client")

	if client.Boolean(ctx, "myflag", true, openfeature.EvaluationContext{}) {
		fmt.Println("myflag is true")
	} else {
		fmt.Println("myflag is false")
	}

}
Output:

myflag is true

func (*Client) BooleanValue

func (c *Client) BooleanValue(ctx context.Context, flag string, defaultValue bool, evalCtx EvaluationContext, options ...Option) (bool, error)

BooleanValue performs a flag evaluation that returns a boolean.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	client := openfeature.NewClient("example-client")
	value, err := client.BooleanValue(
		context.TODO(), "test-flag", true, openfeature.EvaluationContext{},
	)
	if err != nil {
		log.Fatal("error while getting boolean value : ", err)
	}

	fmt.Printf("test-flag value: %v", value)
}
Output:

test-flag value: true

func (*Client) BooleanValueDetails

func (c *Client) BooleanValueDetails(ctx context.Context, flag string, defaultValue bool, evalCtx EvaluationContext, options ...Option) (BooleanEvaluationDetails, error)

BooleanValueDetails performs a flag evaluation that returns an evaluation details struct.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints

func (*Client) EvaluationContext

func (c *Client) EvaluationContext() EvaluationContext

EvaluationContext returns the client's evaluation context

func (*Client) Float added in v1.11.0

func (c *Client) Float(ctx context.Context, flag string, defaultValue float64, evalCtx EvaluationContext, options ...Option) float64

Float performs a flag evaluation that returns a float64. Any error encountered during the evaluation will result in the default value being returned. To explicitly handle errors, use Client.FloatValue or Client.FloatValueDetails

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	ctx := context.TODO()
	client := openfeature.NewClient("example-client")

	fmt.Println(client.Float(ctx, "myflag", 0.5, openfeature.EvaluationContext{}))

}
Output:

0.5

func (*Client) FloatValue

func (c *Client) FloatValue(ctx context.Context, flag string, defaultValue float64, evalCtx EvaluationContext, options ...Option) (float64, error)

FloatValue performs a flag evaluation that returns a float64.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	client := openfeature.NewClient("example-client")
	value, err := client.FloatValue(
		context.TODO(), "test-flag", 0.55, openfeature.EvaluationContext{},
	)
	if err != nil {
		log.Fatalf("error while getting float value: %v", err)
	}

	fmt.Printf("test-flag value: %v", value)
}
Output:

test-flag value: 0.55

func (*Client) FloatValueDetails

func (c *Client) FloatValueDetails(ctx context.Context, flag string, defaultValue float64, evalCtx EvaluationContext, options ...Option) (FloatEvaluationDetails, error)

FloatValueDetails performs a flag evaluation that returns an evaluation details struct.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints

func (*Client) Int added in v1.11.0

func (c *Client) Int(ctx context.Context, flag string, defaultValue int64, evalCtx EvaluationContext, options ...Option) int64

Int performs a flag evaluation that returns an int64. Any error encountered during the evaluation will result in the default value being returned. To explicitly handle errors, use Client.IntValue or Client.IntValueDetails

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	ctx := context.TODO()
	client := openfeature.NewClient("example-client")

	fmt.Println(client.Int(ctx, "myflag", 5, openfeature.EvaluationContext{}))

}
Output:

5

func (*Client) IntValue

func (c *Client) IntValue(ctx context.Context, flag string, defaultValue int64, evalCtx EvaluationContext, options ...Option) (int64, error)

IntValue performs a flag evaluation that returns an int64.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	client := openfeature.NewClient("example-client")
	value, err := client.IntValue(
		context.TODO(), "test-flag", 3, openfeature.EvaluationContext{},
	)
	if err != nil {
		log.Fatalf("error while getting int value: %v", err)
	}

	fmt.Printf("test-flag value: %v", value)
}
Output:

test-flag value: 3

func (*Client) IntValueDetails

func (c *Client) IntValueDetails(ctx context.Context, flag string, defaultValue int64, evalCtx EvaluationContext, options ...Option) (IntEvaluationDetails, error)

IntValueDetails performs a flag evaluation that returns an evaluation details struct.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints

func (*Client) Metadata

func (c *Client) Metadata() ClientMetadata

Metadata returns the client's metadata

func (*Client) Object added in v1.11.0

func (c *Client) Object(ctx context.Context, flag string, defaultValue any, evalCtx EvaluationContext, options ...Option) any

Object performs a flag evaluation that returns an object. Any error encountered during the evaluation will result in the default value being returned. To explicitly handle errors, use Client.ObjectValue or Client.ObjectValueDetails

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	ctx := context.TODO()
	client := openfeature.NewClient("example-client")

	fmt.Println(client.Object(ctx, "myflag", map[string]string{"foo": "bar"}, openfeature.EvaluationContext{}))

}
Output:

map[foo:bar]

func (*Client) ObjectValue

func (c *Client) ObjectValue(ctx context.Context, flag string, defaultValue any, evalCtx EvaluationContext, options ...Option) (any, error)

ObjectValue performs a flag evaluation that returns an object.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	client := openfeature.NewClient("example-client")
	value, err := client.ObjectValue(
		context.TODO(), "test-flag", map[string]string{"foo": "bar"}, openfeature.EvaluationContext{},
	)
	if err != nil {
		log.Fatal("error while getting object value : ", err)
	}

	str, _ := json.Marshal(value)
	fmt.Printf("test-flag value: %v", string(str))
}
Output:

test-flag value: {"foo":"bar"}

func (*Client) ObjectValueDetails

func (c *Client) ObjectValueDetails(ctx context.Context, flag string, defaultValue any, evalCtx EvaluationContext, options ...Option) (InterfaceEvaluationDetails, error)

ObjectValueDetails performs a flag evaluation that returns an evaluation details struct.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints

func (*Client) RemoveHandler

func (c *Client) RemoveHandler(eventType EventType, callback EventCallback)

RemoveHandler allows to remove Client level event handler

func (*Client) SetEvaluationContext

func (c *Client) SetEvaluationContext(evalCtx EvaluationContext)

SetEvaluationContext sets the client's evaluation context

func (*Client) State added in v1.14.0

func (c *Client) State() State

State returns the state of the associated provider

func (*Client) String added in v1.11.0

func (c *Client) String(ctx context.Context, flag string, defaultValue string, evalCtx EvaluationContext, options ...Option) string

String performs a flag evaluation that returns a string. Any error encountered during the evaluation will result in the default value being returned. To explicitly handle errors, use Client.StringValue or Client.StringValueDetails

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	ctx := context.TODO()
	client := openfeature.NewClient("example-client")

	fmt.Println(client.String(ctx, "myflag", "default", openfeature.EvaluationContext{}))

}
Output:

default

func (*Client) StringValue

func (c *Client) StringValue(ctx context.Context, flag string, defaultValue string, evalCtx EvaluationContext, options ...Option) (string, error)

StringValue performs a flag evaluation that returns a string.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints
Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	if err := openfeature.SetNamedProviderAndWait("example-client", openfeature.NoopProvider{}); err != nil {
		log.Fatalf("error setting up provider %v", err)
	}
	client := openfeature.NewClient("example-client")
	value, err := client.StringValue(
		context.TODO(), "test-flag", "openfeature", openfeature.EvaluationContext{},
	)
	if err != nil {
		log.Fatal("error while getting string value : ", err)
	}

	fmt.Printf("test-flag value: %v", value)
}
Output:

test-flag value: openfeature

func (*Client) StringValueDetails

func (c *Client) StringValueDetails(ctx context.Context, flag string, defaultValue string, evalCtx EvaluationContext, options ...Option) (StringEvaluationDetails, error)

StringValueDetails performs a flag evaluation that returns an evaluation details struct.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • flag is the key that uniquely identifies a particular flag
  • defaultValue is returned if an error occurs
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • options are optional additional evaluation options e.g. WithHooks & WithHookHints

func (*Client) Track added in v1.14.0

func (c *Client) Track(ctx context.Context, trackingEventName string, evalCtx EvaluationContext, details TrackingEventDetails)

Track performs an action for tracking for occurrence of a particular action or application state.

Parameters:

  • ctx is the standard go context struct used to manage requests (e.g. timeouts)
  • trackingEventName is the event name to track
  • evalCtx is the evaluation context used in a flag evaluation (not to be confused with ctx)
  • trackingEventDetails defines optional data pertinent to a particular
Example
package main

import (
	"context"

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

func main() {
	ctx := context.TODO()
	client := openfeature.NewClient("example-client")

	evaluationContext := openfeature.EvaluationContext{}

	// example tracking event recording that a subject reached a page associated with a business goal
	client.Track(ctx, "visited-promo-page", evaluationContext, openfeature.TrackingEventDetails{})

	// example tracking event recording that a subject performed an action associated with a business goal, with the tracking event details having a particular numeric value
	client.Track(ctx, "clicked-checkout", evaluationContext, openfeature.NewTrackingEventDetails(99.77))

	// example tracking event recording that a subject performed an action associated with a business goal, with the tracking event details having a particular numeric value
	client.Track(ctx, "clicked-checkout", evaluationContext, openfeature.NewTrackingEventDetails(99.77).Add("currencyCode", "USD"))

}

func (*Client) WithLogger deprecated

func (c *Client) WithLogger(l logr.Logger) *Client

WithLogger sets the logger of the client

Deprecated: use github.com/open-feature/go-sdk/openfeature/hooks.LoggingHook instead.

type ClientMetadata

type ClientMetadata struct {
	// contains filtered or unexported fields
}

ClientMetadata provides a client's metadata

func NewClientMetadata

func NewClientMetadata(domain string) ClientMetadata

NewClientMetadata constructs ClientMetadata Allows for simplified hook test cases while maintaining immutability

func (ClientMetadata) Domain added in v1.12.0

func (cm ClientMetadata) Domain() string

Domain returns the client's domain

func (ClientMetadata) Name deprecated

func (cm ClientMetadata) Name() string

Name returns the client's domain name

Deprecated: Name() exists for historical compatibility, use ClientMetadata.Domain instead.

type ContextAwareStateHandler added in v1.17.0

type ContextAwareStateHandler interface {
	StateHandler // Embed existing interface for backward compatibility
	InitWithContext(ctx context.Context, evaluationContext EvaluationContext) error
	ShutdownWithContext(ctx context.Context) error
}

ContextAwareStateHandler extends StateHandler with context-aware initialization and shutdown for providers that need to respect request timeouts and cancellation. If a provider implements this interface, InitWithContext and ShutdownWithContext will be called instead of Init and Shutdown.

Use this interface when your provider needs to: - Respect initialization/shutdown timeouts (e.g., network calls, database connections) - Support graceful cancellation during setup and teardown - Integrate with request-scoped contexts

Best practices: - Always check ctx.Done() in long-running initialization and shutdown operations - Use reasonable timeout values (typically 5-30 seconds) - Return ctx.Err() when the context is cancelled - Maintain backward compatibility by implementing both interfaces

Example

ExampleContextAwareStateHandler demonstrates how context-aware shutdown works automatically.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

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

func main() {
	// Context-aware providers automatically use ShutdownWithContext when replaced
	provider1 := &openfeature.NoopProvider{}
	provider2 := &openfeature.NoopProvider{}

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	// Set first provider
	err := openfeature.SetProviderWithContextAndWait(ctx, provider1)
	if err != nil {
		log.Printf("Provider setup failed: %v", err)
		return
	}

	// Replace with second provider - this triggers context-aware shutdown of provider1 if it supports it
	err = openfeature.SetProviderWithContextAndWait(ctx, provider2)
	if err != nil {
		log.Printf("Provider replacement failed: %v", err)
		return
	}

	fmt.Println("Context-aware provider lifecycle completed")
}
Output:

Context-aware provider lifecycle completed

type ErrorCode

type ErrorCode string
const (
	// ProviderNotReadyCode - the value was resolved before the provider was ready.
	ProviderNotReadyCode ErrorCode = "PROVIDER_NOT_READY"
	// ProviderFatalCode - a fatal provider error occurred
	ProviderFatalCode ErrorCode = "PROVIDER_FATAL"
	// FlagNotFoundCode - the flag could not be found.
	FlagNotFoundCode ErrorCode = "FLAG_NOT_FOUND"
	// ParseErrorCode - an error was encountered parsing data, such as a flag configuration.
	ParseErrorCode ErrorCode = "PARSE_ERROR"
	// TypeMismatchCode - the type of the flag value does not match the expected type.
	TypeMismatchCode ErrorCode = "TYPE_MISMATCH"
	// TargetingKeyMissingCode - the provider requires a targeting key and one was not provided in the evaluation context.
	TargetingKeyMissingCode ErrorCode = "TARGETING_KEY_MISSING"
	// InvalidContextCode - the evaluation context does not meet provider requirements.
	InvalidContextCode ErrorCode = "INVALID_CONTEXT"
	// GeneralCode - the error was for a reason not enumerated above.
	GeneralCode ErrorCode = "GENERAL"
)

type EvaluationContext

type EvaluationContext struct {
	// contains filtered or unexported fields
}

EvaluationContext provides ambient information for the purposes of flag evaluation The use of the constructor, NewEvaluationContext, is enforced to set EvaluationContext's fields in order to enforce immutability. https://openfeature.dev/specification/sections/evaluation-context

func NewEvaluationContext

func NewEvaluationContext(targetingKey string, attributes map[string]any) EvaluationContext

NewEvaluationContext constructs an EvaluationContext

targetingKey - uniquely identifying the subject (end-user, or client service) of a flag evaluation attributes - contextual data used in flag evaluation

func NewTargetlessEvaluationContext

func NewTargetlessEvaluationContext(attributes map[string]any) EvaluationContext

NewTargetlessEvaluationContext constructs an EvaluationContext with an empty targeting key

attributes - contextual data used in flag evaluation

func TransactionContext added in v1.13.0

func TransactionContext(ctx context.Context) EvaluationContext

TransactionContext extracts a EvaluationContext from the current golang.org/x/net/context. if no EvaluationContext exist, it will construct an empty EvaluationContext

ctx - the context to pull EvaluationContext from

func (EvaluationContext) Attribute

func (e EvaluationContext) Attribute(key string) any

Attribute retrieves the attribute with the given key

func (EvaluationContext) Attributes

func (e EvaluationContext) Attributes() map[string]any

Attributes returns a copy of the EvaluationContext's attributes

func (EvaluationContext) TargetingKey

func (e EvaluationContext) TargetingKey() string

TargetingKey returns the key uniquely identifying the subject (end-user, or client service) of a flag evaluation

type EvaluationDetails

type EvaluationDetails struct {
	FlagKey  string
	FlagType Type
	ResolutionDetail
}

type EvaluationOptions

type EvaluationOptions struct {
	// contains filtered or unexported fields
}

EvaluationOptions should contain a list of hooks to be executed for a flag evaluation

func (EvaluationOptions) HookHints

func (e EvaluationOptions) HookHints() HookHints

HookHints returns evaluation options' hook hints

func (EvaluationOptions) Hooks

func (e EvaluationOptions) Hooks() []Hook

Hooks returns evaluation options' hooks

type Event

type Event struct {
	ProviderName string
	EventType
	ProviderEventDetails
}

Event is an event emitted by a FeatureProvider.

type EventCallback

type EventCallback *func(details EventDetails)

type EventDetails

type EventDetails struct {
	ProviderName string
	ProviderEventDetails
}

type EventHandler

type EventHandler interface {
	EventChannel() <-chan Event
}

EventHandler is the eventing contract enforced for FeatureProvider

type EventType

type EventType string

EventType emitted by a provider implementation

type FeatureProvider

type FeatureProvider interface {
	Metadata() Metadata
	BooleanEvaluation(ctx context.Context, flag string, defaultValue bool, flatCtx FlattenedContext) BoolResolutionDetail
	StringEvaluation(ctx context.Context, flag string, defaultValue string, flatCtx FlattenedContext) StringResolutionDetail
	FloatEvaluation(ctx context.Context, flag string, defaultValue float64, flatCtx FlattenedContext) FloatResolutionDetail
	IntEvaluation(ctx context.Context, flag string, defaultValue int64, flatCtx FlattenedContext) IntResolutionDetail
	ObjectEvaluation(ctx context.Context, flag string, defaultValue any, flatCtx FlattenedContext) InterfaceResolutionDetail
	Hooks() []Hook
}

FeatureProvider interface defines a set of functions that can be called in order to evaluate a flag. This should be implemented by flag management systems.

type FlagMetadata

type FlagMetadata map[string]any

FlagMetadata is a structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, int64 or float64. This structure is populated by a provider for use by an Application Author (via the Evaluation API) or an Application Integrator (via hooks).

func (FlagMetadata) GetBool

func (f FlagMetadata) GetBool(key string) (bool, error)

GetBool fetch bool value from FlagMetadata. Returns an error if the key does not exist, or, the value is of the wrong type

func (FlagMetadata) GetFloat

func (f FlagMetadata) GetFloat(key string) (float64, error)

GetFloat fetch float64 value from FlagMetadata. Returns an error if the key does not exist, or, the value is of the wrong type

func (FlagMetadata) GetInt

func (f FlagMetadata) GetInt(key string) (int64, error)

GetInt fetch int64 value from FlagMetadata. Returns an error if the key does not exist, or, the value is of the wrong type

func (FlagMetadata) GetString

func (f FlagMetadata) GetString(key string) (string, error)

GetString fetch string value from FlagMetadata. Returns an error if the key does not exist, or, the value is of the wrong type

type FlattenedContext

type FlattenedContext map[string]any

FlattenedContext contains metadata for a given flag evaluation in a flattened structure. TargetingKey ("targetingKey") is stored as a string value if provided in the evaluation context.

type FloatEvaluationDetails

type FloatEvaluationDetails = GenericEvaluationDetails[float64]

FloatEvaluationDetails represents the result of the flag evaluation process for float64 flags.

type FloatResolutionDetail

type FloatResolutionDetail = GenericResolutionDetail[float64]

FloatResolutionDetail represents the result of the provider's flag resolution process for float64 flags.

type GenericEvaluationDetails added in v1.16.0

type GenericEvaluationDetails[T any] struct {
	Value T
	EvaluationDetails
}

GenericEvaluationDetails represents the result of the flag evaluation process.

type GenericResolutionDetail added in v1.16.0

type GenericResolutionDetail[T any] struct {
	Value T
	ProviderResolutionDetail
}

GenericResolutionDetail represents the result of the provider's flag resolution process.

type Hook

type Hook interface {
	Before(ctx context.Context, hookContext HookContext, hookHints HookHints) (*EvaluationContext, error)
	After(ctx context.Context, hookContext HookContext, flagEvaluationDetails InterfaceEvaluationDetails, hookHints HookHints) error
	Error(ctx context.Context, hookContext HookContext, err error, hookHints HookHints)
	Finally(ctx context.Context, hookContext HookContext, flagEvaluationDetails InterfaceEvaluationDetails, hookHints HookHints)
}

Hook allows application developers to add arbitrary behavior to the flag evaluation lifecycle. They operate similarly to middleware in many web frameworks. https://github.com/open-feature/spec/blob/main/specification/hooks.md

type HookContext

type HookContext struct {
	// contains filtered or unexported fields
}

HookContext defines the base level fields of a hook context

func NewHookContext

func NewHookContext(
	flagKey string,
	flagType Type,
	defaultValue any,
	clientMetadata ClientMetadata,
	providerMetadata Metadata,
	evaluationContext EvaluationContext,
) HookContext

NewHookContext constructs HookContext Allows for simplified hook test cases while maintaining immutability

func (HookContext) ClientMetadata

func (h HookContext) ClientMetadata() ClientMetadata

ClientMetadata returns the client's metadata

func (HookContext) DefaultValue

func (h HookContext) DefaultValue() any

DefaultValue returns the hook context's default value

func (HookContext) EvaluationContext

func (h HookContext) EvaluationContext() EvaluationContext

EvaluationContext returns the hook context's EvaluationContext

func (HookContext) FlagKey

func (h HookContext) FlagKey() string

FlagKey returns the hook context's flag key

func (HookContext) FlagType

func (h HookContext) FlagType() Type

FlagType returns the hook context's flag type

func (HookContext) ProviderMetadata

func (h HookContext) ProviderMetadata() Metadata

ProviderMetadata returns the provider's metadata

type HookHints

type HookHints struct {
	// contains filtered or unexported fields
}

HookHints contains a map of hints for hooks

func NewHookHints

func NewHookHints(mapOfHints map[string]any) HookHints

NewHookHints constructs HookHints

func (HookHints) Value

func (h HookHints) Value(key string) any

Value returns the value at the given key in the underlying map. Maintains immutability of the map.

type IClient

type IClient interface {
	Metadata() ClientMetadata
	AddHooks(hooks ...Hook)
	SetEvaluationContext(evalCtx EvaluationContext)
	EvaluationContext() EvaluationContext
	BooleanValue(ctx context.Context, flag string, defaultValue bool, evalCtx EvaluationContext, options ...Option) (bool, error)
	StringValue(ctx context.Context, flag string, defaultValue string, evalCtx EvaluationContext, options ...Option) (string, error)
	FloatValue(ctx context.Context, flag string, defaultValue float64, evalCtx EvaluationContext, options ...Option) (float64, error)
	IntValue(ctx context.Context, flag string, defaultValue int64, evalCtx EvaluationContext, options ...Option) (int64, error)
	ObjectValue(ctx context.Context, flag string, defaultValue any, evalCtx EvaluationContext, options ...Option) (any, error)
	BooleanValueDetails(ctx context.Context, flag string, defaultValue bool, evalCtx EvaluationContext, options ...Option) (BooleanEvaluationDetails, error)
	StringValueDetails(ctx context.Context, flag string, defaultValue string, evalCtx EvaluationContext, options ...Option) (StringEvaluationDetails, error)
	FloatValueDetails(ctx context.Context, flag string, defaultValue float64, evalCtx EvaluationContext, options ...Option) (FloatEvaluationDetails, error)
	IntValueDetails(ctx context.Context, flag string, defaultValue int64, evalCtx EvaluationContext, options ...Option) (IntEvaluationDetails, error)
	ObjectValueDetails(ctx context.Context, flag string, defaultValue any, evalCtx EvaluationContext, options ...Option) (InterfaceEvaluationDetails, error)

	Boolean(ctx context.Context, flag string, defaultValue bool, evalCtx EvaluationContext, options ...Option) bool
	String(ctx context.Context, flag string, defaultValue string, evalCtx EvaluationContext, options ...Option) string
	Float(ctx context.Context, flag string, defaultValue float64, evalCtx EvaluationContext, options ...Option) float64
	Int(ctx context.Context, flag string, defaultValue int64, evalCtx EvaluationContext, options ...Option) int64
	Object(ctx context.Context, flag string, defaultValue any, evalCtx EvaluationContext, options ...Option) any

	State() State

	IEventing
	Tracker
}

IClient defines the behaviour required of an OpenFeature client

type IEvaluation added in v1.12.0

type IEvaluation interface {
	SetProvider(provider FeatureProvider) error
	SetProviderAndWait(provider FeatureProvider) error
	GetProviderMetadata() Metadata
	SetNamedProvider(clientName string, provider FeatureProvider, async bool) error
	GetNamedProviderMetadata(name string) Metadata
	GetClient() IClient
	GetNamedClient(clientName string) IClient
	SetEvaluationContext(evalCtx EvaluationContext)
	AddHooks(hooks ...Hook)
	Shutdown()
	ShutdownWithContext(ctx context.Context) error
	IEventing
}

IEvaluation defines the OpenFeature API contract

func GetApiInstance deprecated added in v1.12.0

func GetApiInstance() IEvaluation

GetApiInstance returns the current singleton IEvaluation instance.

Deprecated: use NewDefaultClient or NewClient directly instead

type IEventing added in v1.12.0

type IEventing interface {
	AddHandler(eventType EventType, callback EventCallback)
	RemoveHandler(eventType EventType, callback EventCallback)
}

IEventing defines the OpenFeature eventing contract

type IntEvaluationDetails

type IntEvaluationDetails = GenericEvaluationDetails[int64]

IntEvaluationDetails represents the result of the flag evaluation process for int64 flags.

type IntResolutionDetail

type IntResolutionDetail = GenericResolutionDetail[int64]

IntResolutionDetail represents the result of the provider's flag resolution process for int64 flags.

type InterfaceEvaluationDetails

type InterfaceEvaluationDetails = GenericEvaluationDetails[any]

InterfaceEvaluationDetails represents the result of the flag evaluation process for Object flags.

type InterfaceResolutionDetail

type InterfaceResolutionDetail = GenericResolutionDetail[any]

InterfaceResolutionDetail represents the result of the provider's flag resolution process for Object flags.

type Metadata

type Metadata struct {
	Name string
}

Metadata provides provider name

func NamedProviderMetadata added in v1.12.0

func NamedProviderMetadata(name string) Metadata

NamedProviderMetadata returns the named provider's Metadata

func ProviderMetadata

func ProviderMetadata() Metadata

ProviderMetadata returns the default FeatureProvider metadata

type NoopEventHandler

type NoopEventHandler struct{}

NoopEventHandler is the out-of-the-box EventHandler which is noop

func (NoopEventHandler) EventChannel

func (s NoopEventHandler) EventChannel() <-chan Event

type NoopProvider

type NoopProvider struct{}

NoopProvider implements the FeatureProvider interface and provides functions for evaluating flags

func (NoopProvider) BooleanEvaluation

func (e NoopProvider) BooleanEvaluation(ctx context.Context, flag string, defaultValue bool, flatCtx FlattenedContext) BoolResolutionDetail

BooleanEvaluation returns a boolean flag.

func (NoopProvider) FloatEvaluation

func (e NoopProvider) FloatEvaluation(ctx context.Context, flag string, defaultValue float64, flatCtx FlattenedContext) FloatResolutionDetail

FloatEvaluation returns a float flag.

func (NoopProvider) Hooks

func (e NoopProvider) Hooks() []Hook

Hooks returns hooks

func (NoopProvider) IntEvaluation

func (e NoopProvider) IntEvaluation(ctx context.Context, flag string, defaultValue int64, flatCtx FlattenedContext) IntResolutionDetail

IntEvaluation returns an int flag.

func (NoopProvider) Metadata

func (e NoopProvider) Metadata() Metadata

Metadata returns the metadata of the provider

func (NoopProvider) ObjectEvaluation

func (e NoopProvider) ObjectEvaluation(ctx context.Context, flag string, defaultValue any, flatCtx FlattenedContext) InterfaceResolutionDetail

ObjectEvaluation returns an object flag

func (NoopProvider) StringEvaluation

func (e NoopProvider) StringEvaluation(ctx context.Context, flag string, defaultValue string, flatCtx FlattenedContext) StringResolutionDetail

StringEvaluation returns a string flag.

func (NoopProvider) Track added in v1.14.0

func (e NoopProvider) Track(ctx context.Context, eventName string, evalCtx EvaluationContext, details TrackingEventDetails)

type NoopStateHandler

type NoopStateHandler struct{}

NoopStateHandler is a noop StateHandler implementation

func (*NoopStateHandler) Init

func (*NoopStateHandler) Shutdown

func (s *NoopStateHandler) Shutdown()

type Option

type Option func(*EvaluationOptions)

Option applies a change to EvaluationOptions

func WithHookHints

func WithHookHints(hookHints HookHints) Option

WithHookHints applies provided hook hints.

func WithHooks

func WithHooks(hooks ...Hook) Option

WithHooks applies provided hooks.

type ProviderEventDetails

type ProviderEventDetails struct {
	Message       string
	FlagChanges   []string
	EventMetadata map[string]any
	ErrorCode     ErrorCode
}

ProviderEventDetails is the event payload emitted by FeatureProvider

type ProviderInitError added in v1.14.0

type ProviderInitError struct {
	ErrorCode ErrorCode // Field to store the specific error code
	Message   string    // Custom error message
}

ProviderInitError represents an error that occurs during provider initialization.

func (*ProviderInitError) Error added in v1.14.0

func (e *ProviderInitError) Error() string

Error implements the error interface for ProviderInitError.

type ProviderResolutionDetail

type ProviderResolutionDetail struct {
	ResolutionError ResolutionError
	Reason          Reason
	Variant         string
	FlagMetadata    FlagMetadata
}

ProviderResolutionDetail is a structure which contains a subset of the fields defined in the EvaluationDetail, representing the result of the provider's flag resolution process see https://github.com/open-feature/spec/blob/main/specification/types.md#resolution-details

func (ProviderResolutionDetail) Error

func (p ProviderResolutionDetail) Error() error

func (ProviderResolutionDetail) ResolutionDetail

func (p ProviderResolutionDetail) ResolutionDetail() ResolutionDetail

type Reason

type Reason string

Reason indicates the semantic reason for a returned flag value

type ResolutionDetail

type ResolutionDetail struct {
	Variant      string
	Reason       Reason
	ErrorCode    ErrorCode
	ErrorMessage string
	FlagMetadata FlagMetadata
}

type ResolutionError

type ResolutionError struct {
	// contains filtered or unexported fields
}

ResolutionError is an enumerated error code with an optional message

func NewFlagNotFoundResolutionError

func NewFlagNotFoundResolutionError(msg string) ResolutionError

NewFlagNotFoundResolutionError constructs a resolution error with code FLAG_NOT_FOUND

Explanation - The flag could not be found.

func NewGeneralResolutionError

func NewGeneralResolutionError(msg string, errs ...error) ResolutionError

NewGeneralResolutionError constructs a resolution error with code GENERAL

Explanation - The error was for a reason not enumerated above.

func NewInvalidContextResolutionError

func NewInvalidContextResolutionError(msg string) ResolutionError

NewInvalidContextResolutionError constructs a resolution error with code INVALID_CONTEXT

Explanation - The evaluation context does not meet provider requirements.

func NewParseErrorResolutionError

func NewParseErrorResolutionError(msg string, errs ...error) ResolutionError

NewParseErrorResolutionError constructs a resolution error with code PARSE_ERROR

Explanation - An error was encountered parsing data, such as a flag configuration.

func NewProviderFatalResolutionError added in v1.17.0

func NewProviderFatalResolutionError(msg string) ResolutionError

NewProviderFatalResolutionError constructs a resolution error with code PROVIDER_FATAL

Explanation - The provider is in an irrecoverable error state.

func NewProviderNotReadyResolutionError

func NewProviderNotReadyResolutionError(msg string) ResolutionError

NewProviderNotReadyResolutionError constructs a resolution error with code PROVIDER_NOT_READY

Explanation - The value was resolved before the provider was ready.

func NewTargetingKeyMissingResolutionError

func NewTargetingKeyMissingResolutionError(msg string) ResolutionError

NewTargetingKeyMissingResolutionError constructs a resolution error with code TARGETING_KEY_MISSING

Explanation - The provider requires a targeting key and one was not provided in the evaluation context.

func NewTypeMismatchResolutionError

func NewTypeMismatchResolutionError(msg string) ResolutionError

NewTypeMismatchResolutionError constructs a resolution error with code TYPE_MISMATCH

Explanation - The type of the flag value does not match the expected type.

func (ResolutionError) Error

func (r ResolutionError) Error() string

Error implements the error interface for ResolutionError.

func (ResolutionError) Unwrap added in v1.17.0

func (r ResolutionError) Unwrap() error

Unwrap allows access to the original error, if any.

type State

type State string

State represents the status of the provider

type StateHandler

type StateHandler interface {
	Init(evaluationContext EvaluationContext) error
	Shutdown()
}

StateHandler is the contract for initialization & shutdown. FeatureProvider can opt in for this behavior by implementing the interface

type StringEvaluationDetails

type StringEvaluationDetails = GenericEvaluationDetails[string]

StringEvaluationDetails represents the result of the flag evaluation process for string flags.

type StringResolutionDetail

type StringResolutionDetail = GenericResolutionDetail[string]

StringResolutionDetail represents the result of the provider's flag resolution process for string flags.

type Tracker added in v1.14.0

type Tracker interface {
	Track(ctx context.Context, trackingEventName string, evaluationContext EvaluationContext, details TrackingEventDetails)
}

Tracker is the contract for tracking FeatureProvider can opt in for this behavior by implementing the interface

type TrackingEventDetails added in v1.14.0

type TrackingEventDetails struct {
	// contains filtered or unexported fields
}

TrackingEventDetails provides a tracking details with float64 value

func NewTrackingEventDetails added in v1.14.0

func NewTrackingEventDetails(value float64) TrackingEventDetails

NewTrackingEventDetails return TrackingEventDetails associated with numeric value

func (TrackingEventDetails) Add added in v1.14.0

Add insert new key-value pair into TrackingEventDetails and return the TrackingEventDetails itself. If the key already exists in TrackingEventDetails, it will be replaced.

Usage: trackingEventDetails.Add('active-time', 2).Add('unit': 'seconds')

func (TrackingEventDetails) Attribute added in v1.14.0

func (t TrackingEventDetails) Attribute(key string) any

Attribute retrieves the attribute with the given key.

func (TrackingEventDetails) Attributes added in v1.14.0

func (t TrackingEventDetails) Attributes() map[string]any

Attributes return a map contains the key-value pairs stored in TrackingEventDetails.

func (TrackingEventDetails) Copy added in v1.14.0

Copy return a new TrackingEventDetails with new value. It will copy details of old TrackingEventDetails into the new one to ensure the immutability.

func (TrackingEventDetails) Value added in v1.14.0

func (t TrackingEventDetails) Value() float64

Value retrieves the value of TrackingEventDetails.

type Type

type Type int64

Type represents the type of a flag

const (
	Boolean Type = iota
	String
	Float
	Int
	Object
)

func (Type) String

func (t Type) String() string

type UnimplementedHook

type UnimplementedHook struct{}

UnimplementedHook implements all hook methods with empty functions Include UnimplementedHook in your hook struct to avoid defining empty functions e.g.

type MyHook struct {
  UnimplementedHook
}

func (UnimplementedHook) Before

func (UnimplementedHook) Error

Directories

Path Synopsis
Package hooks provides OpenFeature hooks.
Package hooks provides OpenFeature hooks.
Package internal contains internal identifiers for the OpenFeature SDK.
Package internal contains internal identifiers for the OpenFeature SDK.
Package memprovider provides an in-memory feature flag provider for OpenFeature.
Package memprovider provides an in-memory feature flag provider for OpenFeature.
Package multi is an experimental implementation of a of.FeatureProvider that supports evaluating multiple feature flag providers together.
Package multi is an experimental implementation of a of.FeatureProvider that supports evaluating multiple feature flag providers together.
Package telemetry provides utilities for extracting data from the OpenFeature SDK for use in telemetry signals.
Package telemetry provides utilities for extracting data from the OpenFeature SDK for use in telemetry signals.
Package testing provides a test-aware feature flag provider for OpenFeature.
Package testing provides a test-aware feature flag provider for OpenFeature.

Jump to

Keyboard shortcuts

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