snapshot

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 6 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IFace

type IFace interface {
	// Test if a feature is enabled using the built in random generator. This is done by generating
	// a random number in the range 0-99 and seeing if this number is < the value stored in the
	// runtime key, or the default_value if the runtime key is invalid.
	//
	// NOTE: Although a snapshot represents a stable snapshot *of the contents in runtime*, the behavior of
	//       this function, by design, includes performing a pseudo-random dice roll upon every call to it.
	//       As a result, despite the fact that the underlying snapshot is not changing, the result of calling
	//       this function repeatedly with the same parameter will *not* necessarily yield the same result.
	//       Callers must be careful not to assume that multiple calls with result in a consistent return value.
	//
	//       In other words, the snapshot provides a fixed *probability* of a particular result, but the result
	//       will still vary across calls based on that probability.
	//
	// @param key supplies the feature key to lookup.
	// @param defaultValue supplies the default value that will be used if either the feature key
	//        does not exist or it is not an integer.
	// @return true if the feature is enabled.
	FeatureEnabled(key string, defaultValue uint64) bool

	// FeatureEnabledForID checks that the crc32 of the id and key's byte value falls within the mod of
	// the 0-100 value for the given feature. Use this method for "sticky" features
	// @param key supplies the feature key to lookup.
	// @param id supplies the ID to use in the CRC check.
	// @param defaultValue supplies the default value that will be used if either the feature key
	//        does not exist or it is not a valid percentage.
	FeatureEnabledForID(key string, id uint64, defaultPercentage uint32) bool

	// Fetch raw runtime data based on key.
	// @param key supplies the key to fetch.
	// @return const std::string& the value or empty string if the key does not exist.
	Get(key string) string

	// Fetch an integer runtime key.
	// @param key supplies the key to fetch.
	// @param defaultValue supplies the value to return if the key does not exist or it does not
	//        contain an integer.
	// @return uint64 the runtime value or the default value.
	GetInteger(key string, defaultValue uint64) uint64

	// GetModified returns the last modified timestamp for key. If key does not
	// exist, the zero value for time.Time is returned.
	GetModified(key string) time.Time

	// Fetch all keys inside the snapshot.
	// @return []string all of the keys.
	Keys() []string

	Entries() map[string]*entry.Entry

	SetEntry(string, *entry.Entry)
}

Snapshot provides the currently loaded set of runtime values.

type Mock added in v0.1.1

type Mock struct {
	*Snapshot
}

Mock provides a Snapshot implementation for testing

func NewMock added in v0.1.1

func NewMock() (s *Mock)

NewMock initializes a new Mock

func (*Mock) FeatureEnabled added in v0.1.1

func (m *Mock) FeatureEnabled(key string, defaultValue uint64) bool

FeatureEnabled overrides the internal `Snapshot`s `FeatureEnabled`

func (*Mock) Set added in v0.1.2

func (m *Mock) Set(key string, val string) *Mock

Set set the entry for `key` to `val`

func (*Mock) SetDisabled added in v0.1.1

func (m *Mock) SetDisabled(key string) *Mock

SetDisabled overrides the entry for `key` to be disabled

func (*Mock) SetEnabled added in v0.1.1

func (m *Mock) SetEnabled(key string) *Mock

SetEnabled overrides the entry for `key` to be enabled

func (*Mock) SetUInt64 added in v0.1.4

func (m *Mock) SetUInt64(key string, val uint64) *Mock

SetUInt64 set the entry for `key` to `val` as a uint64

type Nil

type Nil struct{}

Implementation of Snapshot for the nilLoaderImpl.

func NewNil

func NewNil() Nil

func (Nil) Entries

func (Nil) Entries() map[string]*entry.Entry

func (Nil) FeatureEnabled

func (Nil) FeatureEnabled(_ string, defaultValue uint64) bool

func (Nil) FeatureEnabledForID added in v0.1.5

func (Nil) FeatureEnabledForID(string, uint64, uint32) bool

func (Nil) Get

func (Nil) Get(string) string

func (Nil) GetInteger

func (Nil) GetInteger(_ string, defaultValue uint64) uint64

func (Nil) GetModified added in v0.1.8

func (Nil) GetModified(string) time.Time

func (Nil) Keys

func (Nil) Keys() []string

func (Nil) SetEntry

func (Nil) SetEntry(string, *entry.Entry)

type RandomGenerator

type RandomGenerator interface {
	// @return uint64 a new random number.
	Random() uint64
}

Random number generator. Implementations should be thread safe.

type Snapshot

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

Implementation of Snapshot for the filesystem loader.

func New

func New() (s *Snapshot)

func (*Snapshot) Entries

func (s *Snapshot) Entries() map[string]*entry.Entry

func (*Snapshot) FeatureEnabled

func (s *Snapshot) FeatureEnabled(key string, defaultValue uint64) bool

func (*Snapshot) FeatureEnabledForID added in v0.1.4

func (s *Snapshot) FeatureEnabledForID(key string, id uint64, defaultPercentage uint32) bool

FeatureEnabledForID checks that the crc32 of the id and key's byte value falls within the mod of the 0-100 value for the given feature. Use this method for "sticky" features

func (*Snapshot) Get

func (s *Snapshot) Get(key string) string

func (*Snapshot) GetInteger

func (s *Snapshot) GetInteger(key string, defaultValue uint64) uint64

func (*Snapshot) GetModified added in v0.1.8

func (s *Snapshot) GetModified(key string) time.Time

GetModified returns the last modified timestamp for key. If key does not exist, the zero value for time.Time is returned.

func (*Snapshot) Keys

func (s *Snapshot) Keys() []string

func (*Snapshot) SetEntry

func (s *Snapshot) SetEntry(key string, e *entry.Entry)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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