storage

package
v0.0.0-...-202847b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package storage provides the available storage engines for level 1 and level 2 caches.

Use Go build tags to enable special storage clients or file format loading functions. Supported tags are: bigcache (store in big cache), db (store in MySQL/MariaDB), etcdv3 (store in etcd cluster/server), load from json and yaml.

Index

Constants

View Source
const Prefix = "CONFIG" + SlashSeparator

Prefix with which an environment variable must begin with to be considered as a configuration value.

View Source
const SlashSeparator = "__"

SlashSeparator acts as a slash separator for environment keys.

Variables

This section is empty.

Functions

func FromEnvVar

func FromEnvVar(prefix, envVar string) (config.Path, error)

FromEnvVar parses an environment key into a config.Path.

CONFIG__ETCD__CREDENTIALS__USER_NAME => scope.DefaultTypeID, etc/credentials/user_name

func MakeMulti

func MakeMulti(o MultiOptions, ss ...config.Storager) config.Storager

MakeMulti creates a new Multi backend wrapper. Supports other Multi backend wrappers.

func NewLRU

func NewLRU(maxEntries int) config.Storager

NewLRU creates a new lruCache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller. This type does not get exported. WithLRU provides the `lru` cache which implements a fixed-size thread safe LRU cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller. lru cache to limit the amount of request to the backend service. Use function WithLRU to enable it and set the correct max size of the LRU cache. For now this algorithm should be good enough. Can be refactored any time later.

func NewMap

func NewMap(fqPathValue ...string) config.Storager

NewMap creates a new simple key value storage using a map. Mainly used for testing. fqPathValue must be a balanced slice where i=fully qualified path and i+1 the value.

func ToEnvVar

func ToEnvVar(p config.Path) string

ToEnvVar converts a Path to a valid environment key. Returns an empty string in case of an error.

scope.DefaultTypeID, etc/credentials/user_name => CONFIG__ETCD__CREDENTIALS__USER_NAME

func WithLoadEnvironmentVariables

func WithLoadEnvironmentVariables(op EnvOp) config.LoadDataOption

WithLoadEnvironmentVariables reads configuration values from environment variables. A valid env var is always uppercase and [A-Z0-9_].

CONFIG__ETCD__CREDENTIALS__USER_NAME -> etc/credentials/user_name

Env vars (environment variables) can be unset after reading and optionally cached. They can be read during initialization of the storage backend or on each request.

func WithLoadStrings

func WithLoadStrings(fqPathValue ...string) config.LoadDataOption

WithLoadStrings loads a balanced fully qualified path and its stringified value pair into the config.Service. It does not panic when the fqPathValue slice argument isn't balanced, but returns an error. This functional option allows to load immutable values.

Types

type EnvOp

type EnvOp struct {
	// Prefix can be set to as a custom optional Prefix in case where default
	// Prefix does not work.
	Prefix string
}

EnvOp allows to set options when creating a new Environment storage service.

type MultiOptions

type MultiOptions struct {
	// ContextTimeout if greater than zero a timeout will kick in.
	ContextTimeout time.Duration
	WriteDisabled  []bool // TODO implement must be same length as `backends` and defines which backends should ne write
	WriteSerial    bool   // TODO implement
	ReadParallel   bool   // TODO implement
}

MultiOptions provides options for function MakeMulti.

Jump to

Keyboard shortcuts

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