ofrep

package module
v2.0.0-...-92dda15 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

OpenFeature Remote Evaluation Protocol Provider

This is the Go implementation of the OFREP provider. The provider works by evaluating flags against OFREP single flag evaluation endpoint.

Installation

Use OFREP provider with the latest OpenFeature Go SDK

go get go.openfeature.dev/contrib/providers/ofrep/v2

Usage

Initialize the provider with the URL of the OFREP implementing service,

ofrepProvider := ofrep.NewProvider(of.WithBaseURI("http://localhost:8016"))

Then, register the provider with the OpenFeature Go SDK and use derived clients for flag evaluations,

openfeature.SetProvider(context.TODO(), ofrepProvider)

Configuration

You can configure the provider using following configuration options,

Configuration option Details
WithApiKeyAuth Set the token to be used with "X-API-Key" header
WithBearerToken Set the token to be used with "Bearer" HTTP Authorization schema
WithClient Provide a custom, pre-configured http.Client for OFREP service communication
WithHeaderProvider Register a custom header provider for OFREP calls. You may utilize this for custom authentication/authorization headers
WithHeader Set a custom header to be used for authorization
WithBaseURI Set the base URI of the OFREP service
WithTimeout Set the timeout for the http client used for communication with the OFREP service (ignored if custom client is used)

For example, consider below example which sets bearer token and provides a customized http client,

provider := ofrep.NewProvider(
    ofrep.WithBaseURI("http://localhost:8016"),
    ofrep.WithBearerToken("TOKEN"),
    ofrep.WithClient(&http.Client{
        Timeout: 1 * time.Second,
    }))

Documentation

Overview

Package ofrep provides a OpenFeature Provider for interacting with the OFREP service using the OpenFeature Go SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithApiKeyAuth

func WithApiKeyAuth(token string) func(*outbound.Configuration)

WithApiKeyAuth allows to set token to be used for api key authorization

func WithBaseURI

func WithBaseURI(baseURI string) func(*outbound.Configuration)

WithBaseURI allows to override the base URI of the OFREP service

func WithBearerToken

func WithBearerToken(token string) func(*outbound.Configuration)

WithBearerToken allows to set token to be used for bearer token authorization

func WithClient

func WithClient(client *http.Client) func(configuration *outbound.Configuration)

WithClient allows to provide a pre-configured http.Client for the communication with the OFREP service

func WithHeader

func WithHeader(key, value string) func(*outbound.Configuration)

WithHeader allows to set a custom header

func WithHeaderProvider

func WithHeaderProvider(callback outbound.HeaderCallback) func(*outbound.Configuration)

WithHeaderProvider allows to configure a custom header callback to set a custom authorization header

func WithTimeout

func WithTimeout(timeout time.Duration) func(*outbound.Configuration)

WithTimeout allows to configure the timeout for the http client used for communication with the OFREP service. This option is ignored if a custom client is provided via WithClient.

Types

type Evaluator

type Evaluator interface {
	ResolveBoolean(ctx context.Context, key string, defaultValue bool,
		evalCtx map[string]any) of.BoolResolutionDetail
	ResolveString(ctx context.Context, key string, defaultValue string,
		evalCtx map[string]any) of.StringResolutionDetail
	ResolveFloat(ctx context.Context, key string, defaultValue float64,
		evalCtx map[string]any) of.FloatResolutionDetail
	ResolveInt(ctx context.Context, key string, defaultValue int64,
		evalCtx map[string]any) of.IntResolutionDetail
	ResolveObject(ctx context.Context, key string, defaultValue any,
		evalCtx map[string]any) of.ObjectResolutionDetail
}

Evaluator contract for flag evaluation

type Option

type Option func(*outbound.Configuration)

type Provider

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

Provider implementation for OFREP

func NewProvider

func NewProvider(options ...Option) *Provider

NewProvider returns an OFREP provider configured with provided configuration.

func (Provider) BooleanEvaluation

func (p Provider) BooleanEvaluation(ctx context.Context, flag string, defaultValue bool, evalCtx openfeature.FlattenedContext) openfeature.BoolResolutionDetail

func (Provider) FloatEvaluation

func (p Provider) FloatEvaluation(ctx context.Context, flag string, defaultValue float64, evalCtx openfeature.FlattenedContext) openfeature.FloatResolutionDetail

func (Provider) Hooks

func (p Provider) Hooks() []openfeature.Hook

func (Provider) IntEvaluation

func (p Provider) IntEvaluation(ctx context.Context, flag string, defaultValue int64, evalCtx openfeature.FlattenedContext) openfeature.IntResolutionDetail

func (Provider) Metadata

func (p Provider) Metadata() openfeature.Metadata

func (Provider) ObjectEvaluation

func (p Provider) ObjectEvaluation(ctx context.Context, flag string, defaultValue any, evalCtx openfeature.FlattenedContext) openfeature.ObjectResolutionDetail

func (Provider) StringEvaluation

func (p Provider) StringEvaluation(ctx context.Context, flag string, defaultValue string, evalCtx openfeature.FlattenedContext) openfeature.StringResolutionDetail

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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