openfeature

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 10 Imported by: 25

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"

	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

This section is empty.

Functions

func AddHandler

func AddHandler(eventType EventType, callback EventCallback)

AddHandler allows to add API level event handler

func AddHooks

func AddHooks(hooks ...Hook)

AddHooks appends to the collection of any previously added hooks

func RemoveHandler

func RemoveHandler(eventType EventType, callback EventCallback)

RemoveHandler allows to remove API level event handler

func SetEvaluationContext

func SetEvaluationContext(evalCtx EvaluationContext)

SetEvaluationContext sets the global evaluation context.

func SetLogger

func SetLogger(l logr.Logger)

SetLogger sets the global Logger.

func SetNamedProvider

func SetNamedProvider(clientName string, provider FeatureProvider) error

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

func SetNamedProviderAndWait added in v1.10.0

func SetNamedProviderAndWait(clientName string, provider FeatureProvider) error

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

func SetProvider

func SetProvider(provider FeatureProvider) error

SetProvider sets the default provider. 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 provider and waits for its initialization. Returns an error if initialization cause error

func Shutdown

func Shutdown()

Shutdown active providers

Types

type BoolResolutionDetail

type BoolResolutionDetail struct {
	Value bool
	ProviderResolutionDetail
}

BoolResolutionDetail provides a resolution detail with boolean type

type BooleanEvaluationDetails

type BooleanEvaluationDetails struct {
	Value bool
	EvaluationDetails
}

type Client

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

Client implements the behaviour required of an openfeature client

func NewClient

func NewClient(name string) *Client

NewClient returns a new Client. Name is a unique identifier for this client

Example
package main

import (
	"fmt"

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

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

Client Name: example-client

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 [BooleanValue] or [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"

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

func main() {
	ctx := context.Background()
	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() {
	client := openfeature.NewClient("example-client")
	value, err := client.BooleanValue(
		context.Background(), "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 [FloatValue] or [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"

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

func main() {
	ctx := context.Background()
	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() {
	client := openfeature.NewClient("example-client")
	value, err := client.FloatValue(
		context.Background(), "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 [IntValue] or [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"

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

func main() {
	ctx := context.Background()
	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() {
	client := openfeature.NewClient("example-client")
	value, err := client.IntValue(
		context.Background(), "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 interface{}, evalCtx EvaluationContext, options ...Option) interface{}

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 [ObjectValue] or [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"

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

func main() {
	ctx := context.Background()
	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 interface{}, evalCtx EvaluationContext, options ...Option) (interface{}, 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() {
	client := openfeature.NewClient("example-client")
	value, err := client.ObjectValue(
		context.Background(), "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 interface{}, 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) 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 [StringValue] or [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"

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

func main() {
	ctx := context.Background()
	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() {
	client := openfeature.NewClient("example-client")
	value, err := client.StringValue(
		context.Background(), "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) WithLogger

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

WithLogger sets the logger of the client

type ClientMetadata

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

ClientMetadata provides a client's metadata

func NewClientMetadata

func NewClientMetadata(name string) ClientMetadata

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

func (ClientMetadata) Name

func (cm ClientMetadata) Name() string

Name returns the client's name

type ErrorCode

type ErrorCode string
const (
	// ProviderNotReadyCode - the value was resolved before the provider was ready.
	ProviderNotReadyCode ErrorCode = "PROVIDER_NOT_READY"
	// 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]interface{}) 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]interface{}) EvaluationContext

NewTargetlessEvaluationContext constructs an EvaluationContext with an empty targeting key

attributes - contextual data used in flag evaluation

func (EvaluationContext) Attribute

func (e EvaluationContext) Attribute(key string) interface{}

Attribute retrieves the attribute with the given key

func (EvaluationContext) Attributes

func (e EvaluationContext) Attributes() map[string]interface{}

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, evalCtx FlattenedContext) BoolResolutionDetail
	StringEvaluation(ctx context.Context, flag string, defaultValue string, evalCtx FlattenedContext) StringResolutionDetail
	FloatEvaluation(ctx context.Context, flag string, defaultValue float64, evalCtx FlattenedContext) FloatResolutionDetail
	IntEvaluation(ctx context.Context, flag string, defaultValue int64, evalCtx FlattenedContext) IntResolutionDetail
	ObjectEvaluation(ctx context.Context, flag string, defaultValue interface{}, evalCtx 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]interface{}

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]interface{}

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 struct {
	Value float64
	EvaluationDetails
}

type FloatResolutionDetail

type FloatResolutionDetail struct {
	Value float64
	ProviderResolutionDetail
}

FloatResolutionDetail provides a resolution detail with float64 type

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, 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 interface{},
	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() interface{}

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]interface{}) HookHints

NewHookHints constructs HookHints

func (HookHints) Value

func (h HookHints) Value(key string) interface{}

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)
	AddHandler(eventType EventType, callback EventCallback)
	RemoveHandler(eventType EventType, callback EventCallback)
	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 interface{}, evalCtx EvaluationContext, options ...Option) (interface{}, 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 interface{}, 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 interface{}, evalCtx EvaluationContext, options ...Option) interface{}
}

IClient defines the behaviour required of an openfeature client

type IntEvaluationDetails

type IntEvaluationDetails struct {
	Value int64
	EvaluationDetails
}

type IntResolutionDetail

type IntResolutionDetail struct {
	Value int64
	ProviderResolutionDetail
}

IntResolutionDetail provides a resolution detail with int64 type

type InterfaceEvaluationDetails

type InterfaceEvaluationDetails struct {
	Value interface{}
	EvaluationDetails
}

type InterfaceResolutionDetail

type InterfaceResolutionDetail struct {
	Value interface{}
	ProviderResolutionDetail
}

InterfaceResolutionDetail provides a resolution detail with interface{} type

type Metadata

type Metadata struct {
	Name string
}

Metadata provides provider name

func ProviderMetadata

func ProviderMetadata() Metadata

ProviderMetadata returns the default provider's 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, evalCtx FlattenedContext) BoolResolutionDetail

BooleanEvaluation returns a boolean flag.

func (NoopProvider) FloatEvaluation

func (e NoopProvider) FloatEvaluation(ctx context.Context, flag string, defaultValue float64, evalCtx 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, evalCtx 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 interface{}, evalCtx FlattenedContext) InterfaceResolutionDetail

ObjectEvaluation returns an object flag

func (NoopProvider) StringEvaluation

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

StringEvaluation returns a string flag.

type NoopStateHandler

type NoopStateHandler struct {
}

NoopStateHandler is a noop StateHandler implementation Status always set to ReadyState to comply with specification

func (*NoopStateHandler) Init

func (*NoopStateHandler) Shutdown

func (s *NoopStateHandler) Shutdown()

func (*NoopStateHandler) Status

func (s *NoopStateHandler) Status() State

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]interface{}
}

ProviderEventDetails is the event payload emitted by FeatureProvider

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 N.B we could use generics but to support older versions of go for now we will have type specific resolution detail

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) 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) ResolutionError

NewParseErrorResolutionError constructs a resolution error with code PARSE_ERROR

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

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

type State

type State string

State represents the status of the provider

type StateHandler

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

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

type StringEvaluationDetails

type StringEvaluationDetails struct {
	Value string
	EvaluationDetails
}

type StringResolutionDetail

type StringResolutionDetail struct {
	Value string
	ProviderResolutionDetail
}

StringResolutionDetail provides a resolution detail with string type

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

func (UnimplementedHook) Finally

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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