storage

package
v0.0.0-...-e2be882 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BookDir     = "book"
	HistoryDir  = "history"
	RegistryDir = "registry"

	BackTestRegistryPath = "backtest-events"
	EventsPath           = "events"
	SignalsPath          = "signals"

	BackTestInternalPath = "backtest-internal"
	InternalPath         = "internal"
)

Variables

View Source
var (
	NotFoundErr      = errors.New("not found")
	CouldNotLoadErr  = errors.New("could not load")
	UnrecoverableErr = errors.New("unrecoverable error")
)
View Source
var (
	// DefaultDir is the default storage directory
	// TODO : leaving this for now to be able to adjust for the tests
	DefaultDir = "file-storage"
)

Functions

func Add

func Add(registry Registry, key K, value interface{})

func MakePath

func MakePath(parentDir string, fileName string) (string, error)

func Store

func Store(persistence Persistence, key Key, value interface{})

func ToFile

func ToFile(path string, name string, ext string, content []fmt.Stringer) (string, error)

Types

type EventRegistry

type EventRegistry func(path string) (Registry, error)

EventRegistry creates a registry for the given path

func MockEventRegistry

func MockEventRegistry() EventRegistry

type K

type K struct {
	Pair  string `json:"pair"`
	Label string `json:"label"`
}

K is a simplified key for storage

type Key

type Key struct {
	Hash  int64  `json:"hash"`
	Pair  string `json:"pair"`
	Label string `json:"label"`
}

Key is the storage key for a general implementation

func (Key) Path

func (k Key) Path() string

type MockRegistry

type MockRegistry struct {
	Events map[K][]interface{}
}

func NewMockRegistry

func NewMockRegistry() *MockRegistry

func (*MockRegistry) Add

func (m *MockRegistry) Add(key K, value interface{}) error

func (*MockRegistry) Check

func (m *MockRegistry) Check(key K) (map[string]RegistryPath, error)

func (*MockRegistry) GetAll

func (m *MockRegistry) GetAll(key K, value interface{}) error

func (*MockRegistry) GetFor

func (m *MockRegistry) GetFor(key K, value interface{}, filter func(s string) bool) error

func (*MockRegistry) Root

func (m *MockRegistry) Root() string

type MockStorage

type MockStorage struct {
	Elements map[Key]interface{}
}

func NewMockStorage

func NewMockStorage() *MockStorage

func (*MockStorage) FileName

func (m *MockStorage) FileName() string

func (*MockStorage) Load

func (m *MockStorage) Load(k Key, value interface{}) error

func (*MockStorage) Store

func (m *MockStorage) Store(k Key, value interface{}) error

type Persistence

type Persistence interface {
	Store(k Key, value interface{}) error
	Load(k Key, value interface{}) error
}

Persistence is a batch storage that offers the functionality to store and load large objects at once.

type Registry

type Registry interface {
	Add(key K, value interface{}) error
	GetAll(key K, value interface{}) error
	GetFor(key K, value interface{}, filter func(s string) bool) error
	Check(key K) (map[string]RegistryPath, error)
	Root() string
}

Registry is a storage pattern like a logger or event registry. It receives events one by one, but loads all of them at once.

type RegistryPath

type RegistryPath struct {
	Name  string
	Files []string
}

RegistryPath defines a registry path with including files

type Shard

type Shard func(shard string) (Persistence, error)

Shard creates a new storage implementation for the given shard.

func MockShard

func MockShard() Shard

func VoidShard

func VoidShard(table string) Shard

VoidShard creates a new noop shard

type VoidRegistry

type VoidRegistry struct {
}

VoidRegistry is a dummy event logger which ignores all calls

func NewVoidRegistry

func NewVoidRegistry() *VoidRegistry

NewVoidRegistry creates a new noop registry

func (VoidRegistry) Add

func (v VoidRegistry) Add(key K, value interface{}) error

func (VoidRegistry) Check

func (v VoidRegistry) Check(key K) (map[string]RegistryPath, error)

func (VoidRegistry) GetAll

func (v VoidRegistry) GetAll(key K, value interface{}) error

func (VoidRegistry) GetFor

func (v VoidRegistry) GetFor(key K, value interface{}, filter func(s string) bool) error

func (VoidRegistry) Root

func (v VoidRegistry) Root() string

type VoidStorage

type VoidStorage struct {
}

VoidStorage is a noop storage

func NewVoidStorage

func NewVoidStorage() *VoidStorage

NewVoidStorage creates a new noop storage

func (VoidStorage) FileName

func (d VoidStorage) FileName() string

func (VoidStorage) Load

func (d VoidStorage) Load(k Key, value interface{}) error

func (VoidStorage) Store

func (d VoidStorage) Store(k Key, value interface{}) error

Directories

Path Synopsis
file

Jump to

Keyboard shortcuts

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