internal

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const ClientVersionHeader = "prefab-cloud-go-" + Version
View Source
const Version = "0.2.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 Int64Ptr

func Int64Ptr(val int64) *int64

func IntPtr

func IntPtr(val int) *int

func StringPtr

func StringPtr(val string) *string

func Uint32Ptr added in v0.0.7

func Uint32Ptr(val uint32) *uint32

Types

type ConditionMatch

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

type ConfigEvaluator

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

type ConfigMatch

type ConfigMatch struct {
	ConfigID              int64
	ConfigType            prefabProto.ConfigType
	OriginalMatch         *prefabProto.ConfigValue
	Match                 *prefabProto.ConfigValue
	ConfigKey             string
	WeightedValueIndex    *int
	RowIndex              *int
	ConditionalValueIndex *int
	IsMatch               bool
}

func NewConfigMatchFromConditionMatch

func NewConfigMatchFromConditionMatch(conditionMatch ConditionMatch) ConfigMatch

type ConfigParser added in v0.0.7

type ConfigParser interface {
	Parse(data []byte) ([]*prefabProto.Config, int64, error)
}

type ConfigResolver

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

func NewConfigResolver

func NewConfigResolver(configStore ConfigStoreGetter) *ConfigResolver

func (ConfigResolver) Keys added in v0.0.4

func (c ConfigResolver) Keys() []string

func (ConfigResolver) ResolveValue

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

func (ConfigResolver) ResolveValueForConfig added in v0.0.4

func (c ConfigResolver) ResolveValueForConfig(config *prefabProto.Config, contextSet ContextValueGetter, key string) (ConfigMatch, error)

type ConfigRuleEvaluator

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

func NewConfigRuleEvaluator

func NewConfigRuleEvaluator(configStore ConfigStoreGetter, projectEnvIDSupplier 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)
	Keys() []string
	ContextValueGetter
	ProjectEnvIDSupplier
}

TODO: add a `freshen` or similar method

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
	URLs    []string
}

func BuildHTTPClient

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

func (*HTTPClient) Load

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

func (*HTTPClient) LoadFromURI

func (c *HTTPClient) LoadFromURI(uri string, apiKey string, offset int64) (*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 LocalConfigJSONParser added in v0.0.7

type LocalConfigJSONParser struct{}

func (*LocalConfigJSONParser) Parse added in v0.0.7

func (p *LocalConfigJSONParser) Parse(jsonData []byte) ([]*prefabProto.Config, int64, error)

type LocalConfigYamlParser

type LocalConfigYamlParser struct{}

func (*LocalConfigYamlParser) Parse

func (p *LocalConfigYamlParser) Parse(yamlData []byte) ([]*prefabProto.Config, int64, 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