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(provider Provider) (Client, CloseFunc)
- type APIKeyOption
- type AllowHTTPOption
- type Client
- type ClientOptions
- type CloseFunc
- type Provider
- func CachedAPIProvider(ctx context.Context, rk *RepositoryKey, opts ...ProviderOption) (Provider, error)
- func CachedGitFsProvider(ctx context.Context, repoKey *RepositoryKey, path string, ...) (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 FallbackProvider(primary Provider, backup Provider) Provider
- func NewStaticProvider(featureBytes map[string]map[string][]byte) (Provider, error)
- func RetryProvider(f func(context.Context, *RepositoryKey, ...ProviderOption) (Provider, error), ...) (Provider, error)
- type ProviderOption
- type RepositoryKey
- type ServerOption
- type URLOption
- type UpdateIntervalOption
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 configs 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 APIKeyOption ¶ added in v0.2.2
type APIKeyOption struct {
APIKey string
}
type AllowHTTPOption ¶ added in v0.2.3
type AllowHTTPOption struct{}
type Client ¶
type Client interface { GetBool(ctx context.Context, namespace, key string) (bool, error) GetInt(ctx context.Context, namespace, key string) (int64, error) GetFloat(ctx context.Context, namespace, key string) (float64, error) GetString(ctx context.Context, namespace, key string) (string, error) // result should be an empty Go variable that the JSON config // 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, namespace, key string, result interface{}) error // result should be an empty proto message that the proto config // 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, namespace, key string, result proto.Message) error Close(ctx context.Context) error }
Client allows retrieving lekko configs. The appropriate method must be called based on the type of the config. For instance, calling GetBool on an Int config will result in an error.
type ClientOptions ¶
type ClientOptions struct { // 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 { GetBool(ctx context.Context, key string, namespace string) (bool, error) GetInt(ctx context.Context, key string, namespace string) (int64, error) GetFloat(ctx context.Context, key string, namespace string) (float64, error) GetString(ctx context.Context, key string, namespace string) (string, error) GetProto(ctx context.Context, key string, namespace string, result proto.Message) error GetJSON(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 CachedAPIProvider ¶ added in v0.2.2
func CachedAPIProvider( ctx context.Context, rk *RepositoryKey, opts ...ProviderOption, ) (Provider, error)
Constructs a provider that refreshes configs from Lekko backend repeatedly in the background, caching the configs in-memory.
func CachedGitFsProvider ¶ added in v0.2.2
func CachedGitFsProvider( ctx context.Context, repoKey *RepositoryKey, path string, opts ...ProviderOption, ) (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. If api key and url are provided, this provider will send metrics back to lekko. Provide the path to the root of the repository. 'path/.git/' should be a valid directory.
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 FallbackProvider ¶ added in v0.4.0
func NewStaticProvider ¶
func RetryProvider ¶ added in v0.4.0
func RetryProvider(f func( context.Context, *RepositoryKey, ...ProviderOption, ) (Provider, error), ctx context.Context, rk *RepositoryKey, opts ...ProviderOption) (Provider, error)
type ProviderOption ¶ added in v0.1.0
type ProviderOption interface {
// contains filtered or unexported methods
}
func WithAPIKey ¶ added in v0.2.2
func WithAPIKey(apiKey string) ProviderOption
For providers that communicate directly with Lekko backend, api key is required.
func WithAllowHTTP ¶ added in v0.2.3
func WithAllowHTTP() ProviderOption
For connecting to the sidecar without TLS configured.
func WithServerOption ¶ added in v0.2.2
func WithServerOption(port int32) ProviderOption
If this option is set, the cached provider will expose a web server at the provided port for debugging.
func WithURL ¶ added in v0.2.2
func WithURL(url string) ProviderOption
Used to override the default Lekko URL. For API providers, the default url is Lekko backend. For the Sidecar provider, the default URL is on localhost.
func WithUpdateInterval ¶ added in v0.2.2
func WithUpdateInterval(interval time.Duration) ProviderOption
Optionally configure an update interval for the cached provider. If none is provided, a default will be picked.
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
type ServerOption ¶ added in v0.2.2
type ServerOption struct {
Port int32
}