prefab

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package prefab provides a client for fetching configuration and feature flags from the Prefab Cloud API.

Index

Constants

View Source
const (
	// ReturnError will return an error when checking config/flag values if initialization times out
	ReturnError options.OnInitializationFailure = options.ReturnError
	// ReturnNilMatch will continue (generally returning a zero value, ok=false result) if initialization times out
	ReturnNilMatch options.OnInitializationFailure = options.ReturnNilMatch
)

Variables

This section is empty.

Functions

func ExtractValue added in v0.0.4

func ExtractValue(cv *prefabProto.ConfigValue) (any, bool, error)

ExtractValue extracts the underlying value from a ConfigValue. You're unlikely to need this method.

Types

type Client

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

Client is the Prefab client

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates a new Prefab client. It takes options as arguments (e.g. WithAPIKey)

func (*Client) FeatureIsOn

func (c *Client) FeatureIsOn(key string, contextSet ContextSet) (result bool, wasFound bool)

FeatureIsOn returns a bool indicating if a feature is on for a given key and context. It will default to false if the key does not exist.

func (*Client) GetBoolValue

func (c *Client) GetBoolValue(key string, contextSet ContextSet) (value bool, ok bool, err error)

GetBoolValue returns a bool value for a given key and context

func (*Client) GetBoolValueWithDefault

func (c *Client) GetBoolValueWithDefault(key string, contextSet ContextSet, defaultValue bool) (value bool, wasFound bool)

GetBoolValueWithDefault returns a bool value for a given key and context, with a default value if the key does not exist

func (*Client) GetConfig added in v0.0.4

func (c *Client) GetConfig(key string) (*prefabProto.Config, bool)

GetConfig returns a Config object for a given key. You're unlikely to need this method.

func (*Client) GetConfigMatch added in v0.0.4

func (c *Client) GetConfigMatch(key string, contextSet ContextSet) (*ConfigMatch, error)

GetConfigMatch returns a ConfigMatch object for a given key and context. You're unlikely to need this method.

func (*Client) GetDurationValue

func (c *Client) GetDurationValue(key string, contextSet ContextSet) (value time.Duration, ok bool, err error)

GetDurationValue returns a duration value for a given key and context

func (*Client) GetDurationWithDefault

func (c *Client) GetDurationWithDefault(key string, contextSet ContextSet, defaultValue time.Duration) (value time.Duration, wasFound bool)

GetDurationWithDefault returns a duration value for a given key and context, with a default value if the key does not exist

func (*Client) GetFloatValue

func (c *Client) GetFloatValue(key string, contextSet ContextSet) (value float64, ok bool, err error)

GetFloatValue returns a float value for a given key and context

func (*Client) GetFloatValueWithDefault

func (c *Client) GetFloatValueWithDefault(key string, contextSet ContextSet, defaultValue float64) (value float64, wasFound bool)

GetFloatValueWithDefault returns a float value for a given key and context, with a default value if the key does not exist

func (*Client) GetIntValue

func (c *Client) GetIntValue(key string, contextSet ContextSet) (value int64, ok bool, err error)

GetIntValue returns an int value for a given key and context

func (*Client) GetIntValueWithDefault

func (c *Client) GetIntValueWithDefault(key string, contextSet ContextSet, defaultValue int64) (value int64, wasFound bool)

GetIntValueWithDefault returns an int value for a given key and context, with a default value if the key does not exist

func (*Client) GetJSONValue

func (c *Client) GetJSONValue(key string, contextSet ContextSet) (value interface{}, ok bool, err error)

GetJSONValue returns a JSON value for a given key and context

func (*Client) GetJSONValueWithDefault

func (c *Client) GetJSONValueWithDefault(key string, contextSet ContextSet, defaultValue interface{}) (value interface{}, wasFound bool)

GetJSONValueWithDefault returns a JSON value for a given key and context, with a default value if the key does not exist

func (*Client) GetLogLevelStringValue

func (c *Client) GetLogLevelStringValue(key string, contextSet ContextSet) (result string, ok bool, err error)

GetLogLevelStringValue returns a string value for a given key and context, representing a log level.

func (*Client) GetStringSliceValue

func (c *Client) GetStringSliceValue(key string, contextSet ContextSet) (value []string, ok bool, err error)

GetStringSliceValue returns a string slice value for a given key and context

func (*Client) GetStringSliceValueWithDefault

func (c *Client) GetStringSliceValueWithDefault(key string, contextSet ContextSet, defaultValue []string) (value []string, wasFound bool)

GetStringSliceValueWithDefault returns a string slice value for a given key and context, with a default value if the key does not exist

func (*Client) GetStringValue

func (c *Client) GetStringValue(key string, contextSet ContextSet) (value string, ok bool, err error)

GetStringValue returns a string value for a given key and context

func (*Client) GetStringValueWithDefault

func (c *Client) GetStringValueWithDefault(key string, contextSet ContextSet, defaultValue string) (value string, wasFound bool)

GetStringValueWithDefault returns a string value for a given key and context, with a default value if the key does not exist

func (*Client) Keys added in v0.0.4

func (c *Client) Keys() ([]string, error)

Keys returns a list of all keys in the config store

func (*Client) WithContext

func (c *Client) WithContext(contextSet *ContextSet) *ContextBoundClient

WithContext returns a new ContextBoundClient bound to the provided context (merged with the parent context)

type ClientInterface

type ClientInterface interface {
	GetIntValue(key string, contextSet ContextSet) (int64, bool, error)
	GetBoolValue(key string, contextSet ContextSet) (bool, bool, error)
	GetStringValue(key string, contextSet ContextSet) (string, bool, error)
	GetFloatValue(key string, contextSet ContextSet) (float64, bool, error)
	GetStringSliceValue(key string, contextSet ContextSet) ([]string, bool, error)
	GetDurationValue(key string, contextSet ContextSet) (time.Duration, bool, error)
	GetIntValueWithDefault(key string, contextSet ContextSet, defaultValue int64) (int64, bool)
	GetBoolValueWithDefault(key string, contextSet ContextSet, defaultValue bool) (bool, bool)
	GetStringValueWithDefault(key string, contextSet ContextSet, defaultValue string) (string, bool)
	GetFloatValueWithDefault(key string, contextSet ContextSet, defaultValue float64) (float64, bool)
	GetStringSliceValueWithDefault(key string, contextSet ContextSet, defaultValue []string) ([]string, bool)
	GetDurationWithDefault(key string, contextSet ContextSet, defaultValue time.Duration) (time.Duration, bool)
	GetLogLevelStringValue(key string, contextSet ContextSet) (string, bool, error)
	GetJSONValue(key string, contextSet ContextSet) (interface{}, bool, error)
	GetJSONValueWithDefault(key string, contextSet ContextSet, defaultValue interface{}) (interface{}, bool)
	GetConfigMatch(key string, contextSet ContextSet) (*ConfigMatch, error)
	GetConfig(key string) (*prefabProto.Config, bool)
	FeatureIsOn(key string, contextSet ContextSet) (bool, bool)
	WithContext(contextSet *ContextSet) *ContextBoundClient
}

ClientInterface is the interface for the Prefab client

type ConfigMatch added in v0.0.4

type ConfigMatch = internal.ConfigMatch

ConfigMatch represents a match between a config/flag key and a context. It has internal fields that are used by the client to determine the final value and report telemetry.

type ContextBoundClient added in v0.0.4

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

ContextBoundClient is a Client bound to a specific context. Any calls to the client will use the context provided.

func (*ContextBoundClient) FeatureIsOn added in v0.0.4

func (c *ContextBoundClient) FeatureIsOn(key string, contextSet contexts.ContextSet) (result bool, wasFound bool)

FeatureIsOn returns a bool indicating if a feature is on for a given key and context. It will default to false if the key does not exist.

func (*ContextBoundClient) GetBoolValue added in v0.0.4

func (c *ContextBoundClient) GetBoolValue(key string, contextSet contexts.ContextSet) (value bool, ok bool, err error)

GetBoolValue returns a bool value for a given key and context

func (*ContextBoundClient) GetBoolValueWithDefault added in v0.0.4

func (c *ContextBoundClient) GetBoolValueWithDefault(key string, contextSet contexts.ContextSet, defaultValue bool) (value bool, wasFound bool)

GetBoolValueWithDefault returns a bool value for a given key and context, with a default value if the key does not exist

func (*ContextBoundClient) GetConfig added in v0.0.4

func (c *ContextBoundClient) GetConfig(key string) (*prefabProto.Config, bool)

GetConfig returns a Config object for a given key. You're unlikely to need this method.

func (*ContextBoundClient) GetConfigMatch added in v0.0.4

func (c *ContextBoundClient) GetConfigMatch(key string, contextSet ContextSet) (*ConfigMatch, error)

GetConfigMatch returns a ConfigMatch object for a given key and context. You're unlikely to need this method.

func (*ContextBoundClient) GetDurationValue added in v0.0.4

func (c *ContextBoundClient) GetDurationValue(key string, contextSet contexts.ContextSet) (value time.Duration, ok bool, err error)

GetDurationValue returns a duration value for a given key and context

func (*ContextBoundClient) GetDurationWithDefault added in v0.0.4

func (c *ContextBoundClient) GetDurationWithDefault(key string, contextSet contexts.ContextSet, defaultValue time.Duration) (value time.Duration, wasFound bool)

GetDurationWithDefault returns a duration value for a given key and context, with a default value if the key does not exist

func (*ContextBoundClient) GetFloatValue added in v0.0.4

func (c *ContextBoundClient) GetFloatValue(key string, contextSet contexts.ContextSet) (value float64, ok bool, err error)

GetFloatValue returns a float value for a given key and context

func (*ContextBoundClient) GetFloatValueWithDefault added in v0.0.4

func (c *ContextBoundClient) GetFloatValueWithDefault(key string, contextSet contexts.ContextSet, defaultValue float64) (value float64, wasFound bool)

GetFloatValueWithDefault returns a float value for a given key and context, with a default value if the key does not exist

func (*ContextBoundClient) GetIntValue added in v0.0.4

func (c *ContextBoundClient) GetIntValue(key string, contextSet contexts.ContextSet) (value int64, ok bool, err error)

GetIntValue returns an int value for a given key and context

func (*ContextBoundClient) GetIntValueWithDefault added in v0.0.4

func (c *ContextBoundClient) GetIntValueWithDefault(key string, contextSet contexts.ContextSet, defaultValue int64) (value int64, wasFound bool)

GetIntValueWithDefault returns an int value for a given key and context, with a default value if the key does not exist

func (*ContextBoundClient) GetJSONValue added in v0.0.4

func (c *ContextBoundClient) GetJSONValue(key string, contextSet contexts.ContextSet) (value interface{}, ok bool, err error)

GetJSONValue returns a JSON value for a given key and context

func (*ContextBoundClient) GetJSONValueWithDefault added in v0.0.4

func (c *ContextBoundClient) GetJSONValueWithDefault(key string, contextSet contexts.ContextSet, defaultValue interface{}) (value interface{}, wasFound bool)

GetJSONValueWithDefault returns a JSON value for a given key and context, with a default value if the key does not exist

func (*ContextBoundClient) GetLogLevelStringValue added in v0.0.4

func (c *ContextBoundClient) GetLogLevelStringValue(key string, contextSet contexts.ContextSet) (value string, ok bool, err error)

GetLogLevelStringValue returns a string value for a given key and context, representing a log level.

func (*ContextBoundClient) GetStringSliceValue added in v0.0.4

func (c *ContextBoundClient) GetStringSliceValue(key string, contextSet contexts.ContextSet) (value []string, ok bool, err error)

GetStringSliceValue returns a string slice value for a given key and context

func (*ContextBoundClient) GetStringSliceValueWithDefault added in v0.0.4

func (c *ContextBoundClient) GetStringSliceValueWithDefault(key string, contextSet contexts.ContextSet, defaultValue []string) (value []string, wasFound bool)

GetStringSliceValueWithDefault returns a string slice value for a given key and context, with a default value if the key does not exist

func (*ContextBoundClient) GetStringValue added in v0.0.4

func (c *ContextBoundClient) GetStringValue(key string, contextSet contexts.ContextSet) (value string, ok bool, err error)

GetStringValue returns a string value for a given key and context

func (*ContextBoundClient) GetStringValueWithDefault added in v0.0.4

func (c *ContextBoundClient) GetStringValueWithDefault(key string, contextSet contexts.ContextSet, defaultValue string) (value string, wasFound bool)

GetStringValueWithDefault returns a string value for a given key and context, with a default value if the key does not exist

func (*ContextBoundClient) WithContext added in v0.0.4

func (c *ContextBoundClient) WithContext(contextSet *ContextSet) *ContextBoundClient

WithContext returns a new ContextBoundClient bound to the provided context (merged with the parent context)

type ContextSet

type ContextSet = contexts.ContextSet

ContextSet is a set of NamedContext

func NewContextSet added in v0.0.4

func NewContextSet() *ContextSet

NewContextSet creates a new ContextSet

type NamedContext added in v0.0.4

type NamedContext = contexts.NamedContext

NamedContext is a named context. It is used to provide context to the client about the current user/machine/etc.

type Option

type Option func(*options.Options) error

Option is a function that modifies the options for the prefab client.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for the prefab client.

func WithAPIURLs added in v0.0.4

func WithAPIURLs(apiURL []string) Option

WithAPIURLs sets the API URLs for the prefab client.

You likely will never need to use this option.

func WithGlobalContext

func WithGlobalContext(globalContext *ContextSet) Option

WithGlobalContext sets the global context for the prefab client.

func WithInitializationTimeoutSeconds

func WithInitializationTimeoutSeconds(timeoutSeconds float64) Option

WithInitializationTimeoutSeconds sets the initialization timeout for the prefab client. After this time, the client will either raise or continue depending on the OnInitializationFailure option.

func WithOfflineSources added in v0.0.4

func WithOfflineSources(sources []string) Option

WithOfflineSources allows providing customthe sources for the prefab client. Using this option will exclude the default (API + SSE) sources.

Do not use this option if you are using the standard API or SSE sources. Example:

client, err := prefab.NewClient(
	prefab.WithProjectEnvID(projectEnvID),
	prefab.WithOfflineSources([]string{
		"dump://" + fileName,
	}))

func WithOnInitializationFailure

func WithOnInitializationFailure(onInitializationFailure options.OnInitializationFailure) Option

WithOnInitializationFailure sets the behavior for the prefab client when initialization fails.

The default behavior is to return an error when a GetConfig (or similar) call is made (prefab.ReturnError).

If you want to ignore the error and continue, use prefab.ReturnNilMatch.

func WithProjectEnvID added in v0.0.4

func WithProjectEnvID(projectEnvID int64) Option

WithProjectEnvID sets the project environment ID for the prefab client. You only need to set this if you are using a config dump source.

func WithSources added in v0.0.4

func WithSources(sources []string, excludeDefault bool) Option

WithSources allows providing custom sources for the prefab client to use. This prepends your sources to the default sources (API + SSE).

Directories

Path Synopsis
sse

Jump to

Keyboard shortcuts

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