tapedb

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

README

tapedb

Embbeded database for Go programs

Project

The implementation was provided by simia.tech GmbH.

License

The project is licensed under Apache 2.0 (see LICENSE file).

Documentation

Index

Constants

View Source
const (
	FileNameDatabase    = "db"
	FileNameNewDatabase = "db.new"
	FilePrefixPayload   = "payload-"

	HeaderNonce = "Nonce"
)

Variables

View Source
var (
	ErrDatabaseMissing = errors.New("database missing")
	ErrDatabaseExists  = errors.New("database exists")
)
View Source
var (
	ErrPayloadIDAlreadyExists = errors.New("payload id already exists")
	ErrPayloadMissing         = errors.New("payload missing")
)
View Source
var (
	ErrUnknownType = errors.New("unknown type")
)
View Source
var RandomNonce = func() []byte {
	nonce := [12]byte{}
	if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
		panic(err)
	}
	return nonce[:]
}

Functions

func GenerateUUID

func GenerateUUID() string

Types

type Base

type Base interface {
	Apply(Change) error
}

type BaseFactoryFunc

type BaseFactoryFunc func() (Base, error)

func PrototypeBaseFactory

func PrototypeBaseFactory(prototype Base) BaseFactoryFunc

type Change

type Change interface {
	TypeName() string
}

type ChangeFactoryFunc

type ChangeFactoryFunc func(string) (Change, error)

func PrototypeChangeFactory

func PrototypeChangeFactory(prototypes ...Change) ChangeFactoryFunc

type CreateOption

type CreateOption func(*createOptions)

func WithCreateKey

func WithCreateKey(value []byte) CreateOption

func WithCreateKeyFunc

func WithCreateKeyFunc(value KeyFunc) CreateOption

func WithDirectoryMode

func WithDirectoryMode(value fs.FileMode) CreateOption

func WithFileMode

func WithFileMode(value fs.FileMode) CreateOption

func WithHeader

func WithHeader(value Header) CreateOption

type Database

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

func (*Database) Apply

func (db *Database) Apply(change Change) error

func (*Database) ChangesCount

func (db *Database) ChangesCount() int

func (*Database) Header

func (db *Database) Header() Header

func (*Database) State

func (db *Database) State() State

type FileDatabase

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

func (*FileDatabase) Apply

func (db *FileDatabase) Apply(change Change, payloads ...Payload) error

func (*FileDatabase) ChangesCount

func (db *FileDatabase) ChangesCount() int

func (*FileDatabase) Close

func (db *FileDatabase) Close() error

func (*FileDatabase) Header

func (db *FileDatabase) Header() Header

func (*FileDatabase) OpenPayload

func (db *FileDatabase) OpenPayload(id string) (io.ReadCloser, error)

func (*FileDatabase) State

func (db *FileDatabase) State() State

type FileDeck

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

func (*FileDeck) Close

func (d *FileDeck) Close() error

func (*FileDeck) Create

func (d *FileDeck) Create(path string, opts ...CreateOption) error

func (*FileDeck) Delete

func (d *FileDeck) Delete(path string) error

func (*FileDeck) Len

func (d *FileDeck) Len() int

func (*FileDeck) ReadHeader

func (d *FileDeck) ReadHeader(path string) (Header, error)

func (*FileDeck) WithOpen

func (d *FileDeck) WithOpen(path string, opts []OpenOption, fn func(*FileDatabase) error) error
type Header textproto.MIMEHeader

func ReadHeader

func ReadHeader(r io.Reader) (Header, io.Reader, error)

func (Header) Get

func (h Header) Get(key string) string

func (Header) GetBytes

func (h Header) GetBytes(key string, defaultValue []byte) []byte

func (Header) GetUInt64

func (h Header) GetUInt64(key string, defaultValue uint64) uint64

func (Header) Has

func (h Header) Has(key string) bool

func (Header) Set

func (h Header) Set(key, value string)

func (Header) SetBytes

func (h Header) SetBytes(key string, value []byte)

func (Header) SetUInt64

func (h Header) SetUInt64(key string, value uint64)

func (Header) WriteTo

func (h Header) WriteTo(w io.Writer) (int64, error)

type KeyFunc

type KeyFunc func(Header) ([]byte, error)

func StaticKeyFunc

func StaticKeyFunc(value []byte) KeyFunc

type Model

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

func (*Model) CreateDatabase

func (m *Model) CreateDatabase(w io.Writer, opts ...CreateOption) (*Database, error)

func (*Model) CreateFileDatabase

func (m *Model) CreateFileDatabase(path string, opts ...CreateOption) (*FileDatabase, error)

func (*Model) NewFileDeck

func (m *Model) NewFileDeck(openDatabaseLimit int) (*FileDeck, error)

func (*Model) OpenDatabase

func (m *Model) OpenDatabase(rw io.ReadWriter, opts ...OpenOption) (*Database, error)

func (*Model) OpenFileDatabase

func (m *Model) OpenFileDatabase(path string, opts ...OpenOption) (*FileDatabase, error)

func (*Model) ReadFileDatabaseHeader

func (m *Model) ReadFileDatabaseHeader(path string) (Header, error)

func (*Model) SpliceDatabase

func (m *Model) SpliceDatabase(w io.Writer, r io.Reader, opts ...SpliceOption) ([]string, error)

func (*Model) SpliceFileDatabase

func (m *Model) SpliceFileDatabase(path string, opts ...SpliceOption) error

type OpenOption

type OpenOption func(*openOptions)

func WithOpenKey

func WithOpenKey(value []byte) OpenOption

func WithOpenKeyFunc

func WithOpenKeyFunc(value KeyFunc) OpenOption

type Payload

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

func NewPayload

func NewPayload(id string, r io.Reader) Payload

func (*Payload) ID

func (p *Payload) ID() string

type PayloadContainer

type PayloadContainer interface {
	PayloadIDs() []string
}

type SpliceOption

type SpliceOption func(*spliceOptions)

func WithConsumeChanges

func WithConsumeChanges(value int) SpliceOption

func WithSourceKey

func WithSourceKey(value []byte) SpliceOption

func WithSourceKeyFunc

func WithSourceKeyFunc(value KeyFunc) SpliceOption

func WithTargetKey

func WithTargetKey(value []byte) SpliceOption

func WithTargetKeyFunc

func WithTargetKeyFunc(value KeyFunc) SpliceOption

type State

type State interface {
	Apply(Change) error
}

type StateFactoryFunc

type StateFactoryFunc func(Base, sync.Locker) (State, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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