Documentation
¶
Index ¶
- func Add(ctx context.Context, key string, value interface{}) context.Context
- func Merge(ctx context.Context, lekkoCtx map[string]interface{}) context.Context
- func NewClient(namespace string, provider Provider) (Client, CloseFunc)
- type Client
- type ClientOptions
- type CloseFunc
- type Provider
- func BackendInMemoryProvider(ctx context.Context, apiKey string, repoKey RepositoryKey, ...) (Provider, error)
- func ConnectAPIProvider(ctx context.Context, apiKey string, rk *RepositoryKey, opts ...ProviderOption) (Provider, error)
- func ConnectSidecarProvider(ctx context.Context, url string, rk *RepositoryKey, opts ...ProviderOption) (Provider, error)
- func GitInMemoryProvider(ctx context.Context, path, apiKey string, repoKey RepositoryKey) (Provider, error)
- func GitLocalInMemoryProvider(ctx context.Context, path string, repoKey RepositoryKey) (Provider, error)
- type ProviderOption
- type RepositoryKey
- type URLOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Merge ¶
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.
Types ¶
type Client ¶
type Client interface {
GetBool(ctx context.Context, key string) (bool, error)
GetInt(ctx context.Context, key string) (int64, error)
GetFloat(ctx context.Context, key string) (float64, error)
GetString(ctx context.Context, key string) (string, error)
// result should be an empty Go variable that the JSON feature
// can be unmarshalled into. If an error is returned, the data
// stored in result is unpredictable and should not be relied upon.
GetJSON(ctx context.Context, key string, result interface{}) error
// result should be an empty proto message that the proto feature
// can be unmarshalled into. If an error is returned, the data
// stored in result is unpredictable and should not be relied upon.
GetProto(ctx context.Context, key string, result proto.Message) error
}
Client allows retrieving lekko features. The appropriate method must be called based on the type of the feature. For instance, calling GetBool on an Int feature will result in an 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{}
}
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 BackendInMemoryProvider ¶ added in v0.2.0
func BackendInMemoryProvider(ctx context.Context, apiKey string, repoKey RepositoryKey, updateInterval time.Duration) (Provider, error)
Constructs a provider that refreshes configs from Lekko backend repeatedly in the background, caching the configs in-memory.
func ConnectAPIProvider ¶ added in v0.0.3
func ConnectAPIProvider(ctx context.Context, apiKey string, rk *RepositoryKey, opts ...ProviderOption) (Provider, error)
Fetches configuration directly from Lekko Backend APIs.
func ConnectSidecarProvider ¶ added in v0.0.3
func ConnectSidecarProvider(ctx context.Context, url string, rk *RepositoryKey, opts ...ProviderOption) (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 GitInMemoryProvider ¶ added in v0.2.1
func GitInMemoryProvider(ctx context.Context, path, apiKey string, repoKey RepositoryKey) (Provider, error)
Reads configuration from a git repository on-disk. This provider will remain up to date with changes made to the git repository on-disk. If on-disk contents change, this provider's internal state will be updated without restart. This provider requires an api key to communicate with Lekko. Provide the path to the root of the repository. 'path/.git/' should be a valid directory.
func GitLocalInMemoryProvider ¶ added in v0.2.1
func GitLocalInMemoryProvider(ctx context.Context, path string, repoKey RepositoryKey) (Provider, error)
Reads configuration from a git repository on-disk. This provider will remain up to date with changes made to the git repository on-disk. If on-disk contents change, this provider's internal state will be updated without restart. This provider does not require an api key and can be used while developing locally. Provide the path to the root of the repository. 'path/.git/' should be a valid directory.
type ProviderOption ¶ added in v0.1.0
type ProviderOption interface {
// contains filtered or unexported methods
}
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