client

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	LekkoURL          = "https://prod.api.lekko.dev"
	LekkoAPIKeyHeader = "apikey"
)

Variables

This section is empty.

Functions

func Add

func Add(ctx context.Context, key string, value interface{}) context.Context

func Merge

func Merge(ctx context.Context, lekkoCtx map[string]interface{}) context.Context

Merge allows you to pass arbitrary context variables in order to perform rules evaluation on your feature flags in real time. Priority is given to newly added keys in lekkoCtx. TODO: allow users to run in safe mode, which will throw errors on ctx conflicts. TODO: this is not thread-safe, make it thread-safe.

func NewClient

func NewClient(namespace string, provider Provider) (*Client, CloseFunc)

A function is returned to close the client. It is also strongly recommended to call this when the program is exiting or the lekko provider is no longer needed.

Types

type Client

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

func (*Client) GetBool

func (c *Client) GetBool(ctx context.Context, key string) (bool, error)

func (*Client) GetFloat added in v0.0.2

func (c *Client) GetFloat(ctx context.Context, key string) (float64, error)

func (*Client) GetInt added in v0.0.2

func (c *Client) GetInt(ctx context.Context, key string) (int64, error)

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, key string, result interface{}) error

func (*Client) GetProto

func (c *Client) GetProto(ctx context.Context, key string, result proto.Message) error

func (*Client) GetString added in v0.0.2

func (c *Client) GetString(ctx context.Context, key string) (string, error)

type ClientOptions

type ClientOptions struct {
	// Lekko namespace to read configurations from
	Namespace string
	// Arbitrary keys and values for rules evaluation that are
	// injected into the context at startup. Context keys passed
	// at runtime will override these values in case of conflict.
	StartupContext map[string]interface{}
}

func (ClientOptions) NewClient

func (o ClientOptions) NewClient(provider Provider) *Client

type CloseFunc added in v0.0.3

type CloseFunc func(context.Context) error

type Provider

type Provider interface {
	GetBoolFeature(ctx context.Context, key string, namespace string) (bool, error)
	GetIntFeature(ctx context.Context, key string, namespace string) (int64, error)
	GetFloatFeature(ctx context.Context, key string, namespace string) (float64, error)
	GetStringFeature(ctx context.Context, key string, namespace string) (string, error)
	GetProtoFeature(ctx context.Context, key string, namespace string, result proto.Message) error
	GetJSONFeature(ctx context.Context, key string, namespace string, result interface{}) error
	// Error will get called by the closure returned in Client initialization.
	Close(ctx context.Context) error
}

A provider evaluates configuration from a number of sources.

func ConnectAPIProvider added in v0.0.3

func ConnectAPIProvider(ctx context.Context, apiKey string, rk *RepositoryKey) (Provider, error)

Fetches configuration directly from Lekko Backend APIs. This also make repeated RPCs to register the client, so providing a context with a timeout is strongly recommended.

func ConnectSidecarProvider added in v0.0.3

func ConnectSidecarProvider(ctx context.Context, url, apiKey string, rk *RepositoryKey) (Provider, error)

Fetches configuration from a lekko sidecar, likely running on the local network. Will make repeated RPCs to register the client, so providing context with a timeout is strongly preferred. A function is returned to close the client. It is also strongly recommended to call this when the program is exiting or the lekko provider is no longer needed.

func NewStaticProvider

func NewStaticProvider(pathToRoot string) (Provider, error)

The static provider will read from a git repo via a relative path. This may be useful for local testing when a sidecar is not available.

type RepositoryKey

type RepositoryKey struct {
	// The name of the github owner. Can be a github
	// organization name or a personal account name.
	OwnerName string
	// The name of the repository on github.
	RepoName string
}

Identifies a configuration repository on github.com

Jump to

Keyboard shortcuts

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