storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Closer

type Closer interface {
	Close() error
}

Closer is an interface that wraps around the standard Close method.

type Engine

type Engine uint8

Engine is the enum type for StorageEngine

const (
	MemoryEngine Engine
	RedisEngine
)

Enum types for Storage Engine

type GetSetCloser

type GetSetCloser interface {
	Getter
	Setter
	Closer
}

GetSetCloser is the interface that groups the basic Get, Set and Close methods.

func New

func New(opts ...Option) (GetSetCloser, error)

New is a helper function that takes an arbitrary number of options and returns a GetSetCloser interface

type Getter

type Getter interface {
	Get(key string) ([]byte, error)
}

Getter is an interface that wraps around the standard Get method.

type MemoryStore

type MemoryStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MemoryStore is the primary in-memory data storage and retrieval struct. It contains a sync.RWMutex and an internal map of `map[string][]byte` to store state that conforms to the Storage interface.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore returns a reference to a MemoryStore with an initialized internal map

func (*MemoryStore) Close

func (s *MemoryStore) Close() error

Close implements the standard Close method for storage.

func (*MemoryStore) Get

func (s *MemoryStore) Get(key string) ([]byte, error)

Get takes a key string and returns a byte slice and error. This method uses read locks. It returns an error if the key is not found.

func (*MemoryStore) Set

func (s *MemoryStore) Set(key string, value []byte, ttl time.Duration, timestamp time.Time) error

Set takes a key string and byte slice value and returns an error. It uses a mutex write lock for safety. If an existing key value pair exists, it checks the timestamp and rejects <= timestamp submissions.

type Option

type Option func(*options)

Option is used for special Settings in Storage

func WithEngine

func WithEngine(e Engine) Option

WithEngine takes an Engine and returns an Option.

func WithRedisOptions

func WithRedisOptions(opts ...RedisOption) Option

WithRedisOptions takes an arbitrary number of RedisOption and returns a Option

type RedisOption

type RedisOption func(*redisOptions)

RedisOption is used for special Settings in Storage

func WithRedisAuth

func WithRedisAuth(a string) RedisOption

WithRedisAuth takes a string and returns an RedisOption

func WithRedisDialTLSSkipVerify

func WithRedisDialTLSSkipVerify(b bool) RedisOption

WithRedisDialTLSSkipVerify takes a bool and returns an RedisOption

func WithRedisEndpoint

func WithRedisEndpoint(e string) RedisOption

WithRedisEndpoint takes a string and returns an RedisOption

func WithRedisIdleTimeout

func WithRedisIdleTimeout(d time.Duration) RedisOption

WithRedisIdleTimeout takes a time.Duration and returns an RedisOption

func WithRedisMaxActive

func WithRedisMaxActive(m int) RedisOption

WithRedisMaxActive takes an int and returns an RedisOption

func WithRedisMaxConnLifetime

func WithRedisMaxConnLifetime(d time.Duration) RedisOption

WithRedisMaxConnLifetime takes a bool and returns an RedisOption

func WithRedisMaxIdle

func WithRedisMaxIdle(m int) RedisOption

WithRedisMaxIdle takes an int and returns an RedisOption

func WithRedisTLS

func WithRedisTLS(b bool) RedisOption

WithRedisTLS takes a bool and returns an RedisOption

func WithRedisWait

func WithRedisWait(b bool) RedisOption

WithRedisWait takes a bool and returns an RedisOption

type RedisStore

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

RedisStore is a struct with methods that conforms to the Storage Interface

func NewRedisStore

func NewRedisStore(opts ...RedisOption) *RedisStore

NewRedisStore returns a RedisStore with StorageOptions mapped to Redis Pool settings. Optionally, if Auth is set, Auth is configured on Dial

func (*RedisStore) Close

func (s *RedisStore) Close() error

Close implements the standard Close method for storage

func (*RedisStore) Get

func (s *RedisStore) Get(key string) ([]byte, error)

Get method for RedisStore

func (*RedisStore) Set

func (s *RedisStore) Set(key string, value []byte, ttl time.Duration, timestamp time.Time) error

Set method takes a key, value, and options and saves the base64 encoded value to redis. It returns an error if one is generated by redis

type Setter

type Setter interface {
	Set(key string, value []byte, ttl time.Duration, timestamp time.Time) error
}

Setter is an interface that wraps around the standard Set method. To Prevent replay attacks, the ttl set on key should never be less than the minimumTTL, which is 2x the payload.MaxSubmitWindow. This prevents a specific type of replay attack in which a short-lived TTL is set, below the SubmitWindow horizon, and a slightly older message, also within the SubmitWindow time horizon is replayed and accepted due to no previous key being in the system. Timestamps outside of this window should be automatically forward-looking, but a proper Set method should always check that the submitted timestamp is greater than the existing one, if an existing one is found.

Jump to

Keyboard shortcuts

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