internal

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const ClientVersionHeader = "prefab-cloud-go-" + Version
View Source
const Version = "0.1.0"

Variables

View Source
var (
	ErrConfigDoesNotExist = errors.New("config does not exist")
	ErrEnvVarNotExist     = errors.New("environment variable does not exist")
	ErrTypeCoercionFailed = errors.New("type coercion failed on value from environment variable")
)
View Source
var ErrInvalidValueFormat = errors.New("invalid value format")

Functions

func BoolPtr

func BoolPtr(val bool) *bool

func BuildSSEClient

func BuildSSEClient(options options.Options) (*sse.Client, error)

func Int64Ptr

func Int64Ptr(val int64) *int64

func IntPtr

func IntPtr(val int) *int

func StartSSEConnection

func StartSSEConnection(client *sse.Client, apiConfigStore *APIConfigStore)

func StringPtr

func StringPtr(val string) *string

Types

type APIConfigStore

type APIConfigStore struct {
	sync.RWMutex
	Initialized bool
	// contains filtered or unexported fields
}

func BuildAPIConfigStore

func BuildAPIConfigStore() *APIConfigStore

func (*APIConfigStore) GetConfig

func (cs *APIConfigStore) GetConfig(key string) (*prefabProto.Config, bool)

GetConfig retrieves a Config associated with the given key. It returns a pointer to the Config and a boolean value. The Config pointer is nil if the key does not exist in the store. The boolean value is true if the key exists, and false otherwise.

func (*APIConfigStore) GetContextValue

func (cs *APIConfigStore) GetContextValue(propertyName string) (interface{}, bool)

func (*APIConfigStore) GetProjectEnvID

func (cs *APIConfigStore) GetProjectEnvID() int64

func (*APIConfigStore) Len

func (cs *APIConfigStore) Len() int

func (*APIConfigStore) SetConfigs

func (cs *APIConfigStore) SetConfigs(configs []*prefabProto.Config, envID int64)

func (*APIConfigStore) SetFromConfigsProto

func (cs *APIConfigStore) SetFromConfigsProto(configs *prefabProto.Configs)

type CompositeConfigStore

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

CompositeConfigStore is a config store that composes multiple config stores. It attempts to find a config by key in each store in the order they were provided. The first store that contains the requested config is used, and the search stops. If no store contains the requested config, the CompositeConfigStore returns false to indicate that the config does not exist.

func BuildCompositeConfigStore

func BuildCompositeConfigStore(stores ...ConfigStoreGetter) *CompositeConfigStore

func (*CompositeConfigStore) GetConfig

func (s *CompositeConfigStore) GetConfig(key string) (*prefabProto.Config, bool)

type ConditionMatch

type ConditionMatch struct {
	Match                    *prefabProto.ConfigValue
	SelectedConditionalValue *prefabProto.ConditionalValue
	RowIndex                 int
	ConditionalValueIndex    int
	IsMatch                  bool
}

type ConfigEvaluator

type ConfigEvaluator interface {
	EvaluateConfig(config *prefabProto.Config, contextSet ContextValueGetter) (match ConditionMatch)
}

type ConfigMatch

type ConfigMatch struct {
	OriginalMatch            *prefabProto.ConfigValue
	Match                    *prefabProto.ConfigValue
	WeightedValueIndex       *int
	SelectedConditionalValue *prefabProto.ConditionalValue
	OriginalKey              string
	RowIndex                 int
	ConditionalValueIndex    int
	IsMatch                  bool
}

func NewConfigMatchFromConditionMatch

func NewConfigMatchFromConditionMatch(conditionMatch ConditionMatch) ConfigMatch

type ConfigResolver

type ConfigResolver struct {
	ConfigStore           ConfigStoreGetter
	RuleEvaluator         ConfigEvaluator
	WeightedValueResolver WeightedValueResolverIF
	Decrypter             Decrypter
	EnvLookup             EnvLookup
	ContextGetter         ContextValueGetter
}

func NewConfigResolver

func NewConfigResolver(configStore ConfigStoreGetter, supplier ProjectEnvIDSupplier, apiContextGetter ContextValueGetter) *ConfigResolver

func (ConfigResolver) ResolveValue

func (c ConfigResolver) ResolveValue(key string, contextSet ContextValueGetter) (ConfigMatch, error)

type ConfigRuleEvaluator

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

func NewConfigRuleEvaluator

func NewConfigRuleEvaluator(configStore ConfigStoreGetter, supplier ProjectEnvIDSupplier) *ConfigRuleEvaluator

func (*ConfigRuleEvaluator) EvaluateConditionalValue

func (cve *ConfigRuleEvaluator) EvaluateConditionalValue(conditionalValue *prefabProto.ConditionalValue, contextSet ContextValueGetter) (*prefabProto.ConfigValue, bool)

func (*ConfigRuleEvaluator) EvaluateConfig

func (cve *ConfigRuleEvaluator) EvaluateConfig(config *prefabProto.Config, contextSet ContextValueGetter) ConditionMatch

func (*ConfigRuleEvaluator) EvaluateCriterion

func (cve *ConfigRuleEvaluator) EvaluateCriterion(criterion *prefabProto.Criterion, contextSet ContextValueGetter) bool

func (*ConfigRuleEvaluator) EvaluateRow

func (cve *ConfigRuleEvaluator) EvaluateRow(row *prefabProto.ConfigRow, contextSet ContextValueGetter, rowIndex int) ConditionMatch

type ConfigStoreGetter

type ConfigStoreGetter interface {
	GetConfig(key string) (config *prefabProto.Config, exists bool)
}

type ContextValueGetter

type ContextValueGetter interface {
	GetContextValue(propertyName string) (value interface{}, valueExists bool)
}

type Decrypter

type Decrypter interface {
	DecryptValue(secretKey string, value string) (decryptedValue string, err error)
}

type Encryption

type Encryption struct{}

func (*Encryption) DecryptValue

func (d *Encryption) DecryptValue(secretKeyString string, value string) (string, error)

type EnvLookup

type EnvLookup interface {
	LookupEnv(key string) (string, bool)
}

type HTTPClient

type HTTPClient struct {
	Options *options.Options
	// contains filtered or unexported fields
}

func BuildHTTPClient

func BuildHTTPClient(options options.Options) (*HTTPClient, error)

func (*HTTPClient) Load

func (c *HTTPClient) Load(offset int32) (*prefabProto.Configs, error)

func (*HTTPClient) LoadFromURI

func (c *HTTPClient) LoadFromURI(uri string, apiKey string, offset int32) (*prefabProto.Configs, error)

type Hasher

type Hasher interface {
	HashZeroToOne(value string) (zeroToOne float64, ok bool)
}

type Hashing

type Hashing struct{}

func (Hashing) HashZeroToOne

func (Hashing) HashZeroToOne(value string) (float64, bool)

type LocalConfigStore

type LocalConfigStore struct {
	Initialized bool
	// contains filtered or unexported fields
}

func NewLocalConfigStore

func NewLocalConfigStore(sourceDirectory string, options *options.Options) *LocalConfigStore

func (*LocalConfigStore) GetConfig

func (s *LocalConfigStore) GetConfig(key string) (*prefabProto.Config, bool)

type LocalConfigYamlParser

type LocalConfigYamlParser struct{}

func (*LocalConfigYamlParser) Parse

func (p *LocalConfigYamlParser) Parse(yamlData []byte) ([]*prefabProto.Config, error)

type ProjectEnvIDSupplier

type ProjectEnvIDSupplier interface {
	GetProjectEnvID() int64
}

type Randomer

type Randomer interface {
	Float64() float64
}

type RealEnvLookup

type RealEnvLookup struct{}

func (RealEnvLookup) LookupEnv

func (RealEnvLookup) LookupEnv(key string) (string, bool)

type WeightedValueResolver

type WeightedValueResolver struct {
	Rand   Randomer
	Hasher Hasher
}

func NewWeightedValueResolver

func NewWeightedValueResolver(seed int64, hasher Hasher) *WeightedValueResolver

func (*WeightedValueResolver) Resolve

func (wve *WeightedValueResolver) Resolve(weightedValues *prefabProto.WeightedValues, propertyName string, contextGetter ContextValueGetter) (*prefabProto.ConfigValue, int)

type WeightedValueResolverIF

type WeightedValueResolverIF interface {
	Resolve(weightedValues *prefabProto.WeightedValues, propertyName string, contextGetter ContextValueGetter) (valueResult *prefabProto.ConfigValue, index int)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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