flipt

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

This package provides a Flipt OpenFeature Provider for interacting with the Flipt service backend using the OpenFeature Go SDK.

From the OpenFeature Specification: Providers are the "translator" between the flag evaluation calls made in application code, and the flag management system that stores flags and in some cases evaluates flags.

You can configure the provider to connect to Flipt using any of the provided "Option"s. This configuration allows you to specify the "[ServiceType]" (protocol), and to configure the host, port and other properties to connect to the Flipt service.

Example
package main

import (
	"context"

	"github.com/open-feature/go-sdk/pkg/openfeature"
	"go.flipt.io/flipt-openfeature-provider/pkg/provider/flipt"
)

func main() {
	openfeature.SetProvider(flipt.NewProvider(
		flipt.WithAddress("localhost:9000"),
	))

	client := openfeature.NewClient("my-app")
	value, err := client.BooleanValue(
		context.Background(), "v2_enabled", false, openfeature.NewEvaluationContext("tim@apple.com", map[string]interface{}{
			"favorite_color": "blue",
		}),
	)

	if err != nil {
		panic(err)
	}

	if value {
		// do something
	} else {
		// do something else
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Address         string
	CertificatePath string
	TokenProvider   sdk.ClientTokenProvider
	Namespace       string
}

Config is a configuration for the FliptProvider.

type Option

type Option func(*Provider)

Option is a configuration option for the provider.

func ForNamespace added in v0.1.5

func ForNamespace(namespace string) Option

ForNamespace sets the namespace for flag lookup and evaluation in Flipt.

func WithAddress added in v0.1.2

func WithAddress(address string) Option

WithAddress sets the address for the remote Flipt gRPC or HTTP API.

func WithCertificatePath

func WithCertificatePath(certificatePath string) Option

WithCertificatePath is an Option to set the certificate path (grpc only).

func WithClientTokenProvider added in v0.1.5

func WithClientTokenProvider(tokenProvider sdk.ClientTokenProvider) Option

WithClientTokenProvider sets the token provider for auth to support client auth needs.

func WithConfig

func WithConfig(config Config) Option

WithConfig is an Option to set the entire configuration.

func WithService

func WithService(svc Service) Option

WithService is an Option to set the service for the Provider.

type Provider

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

Provider implements the FeatureProvider interface and provides functions for evaluating flags with Flipt.

func NewProvider

func NewProvider(opts ...Option) *Provider

NewProvider returns a new Flipt provider.

func (Provider) BooleanEvaluation

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

BooleanEvaluation returns a boolean flag.

func (Provider) FloatEvaluation

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

FloatEvaluation returns a float flag.

func (Provider) Hooks

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

Hooks returns hooks.

func (Provider) IntEvaluation

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

IntEvaluation returns an int flag.

func (Provider) Metadata

func (p Provider) Metadata() of.Metadata

Metadata returns the metadata of the provider.

func (Provider) ObjectEvaluation

func (p Provider) ObjectEvaluation(ctx context.Context, flag string, defaultValue interface{}, evalCtx of.FlattenedContext) of.InterfaceResolutionDetail

ObjectEvaluation returns an object flag with attachment if any. Value is a map of key/value pairs ([string]interface{}).

func (Provider) StringEvaluation

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

StringEvaluation returns a string flag.

type Service added in v0.1.2

type Service interface {
	GetFlag(ctx context.Context, namespaceKey, flagKey string) (*flipt.Flag, error)
	Evaluate(ctx context.Context, namespaceKey, flagKey string, evalCtx map[string]interface{}) (*evaluation.VariantEvaluationResponse, error)
	Boolean(ctx context.Context, namespaceKey, flagKey string, evalCtx map[string]interface{}) (*evaluation.BooleanEvaluationResponse, error)
}

Jump to

Keyboard shortcuts

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