filesystem

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package persist defines the basic requirements that the object model expects in order to save and load state. The object model expects to be spun up and down frequently.

Index

Constants

View Source
const ConfigFilename = "config.json"

ConfigFilename is the path relative to the filesystem root where the JSON based configuration file can be found.

View Source
const (
	FormatJson = "json"
)
View Source
const ObjectsDir = "objects"

ObjectsDir is the name of the directory that holds marshaled IDer objects.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrEmptyBankRecordID

type ErrEmptyBankRecordID struct{}

func (ErrEmptyBankRecordID) Error

func (err ErrEmptyBankRecordID) Error() string

type ErrUnsupportedConfiguration added in v0.4.0

type ErrUnsupportedConfiguration RepositoryConfig

func (ErrUnsupportedConfiguration) Error added in v0.4.0

func (err ErrUnsupportedConfiguration) Error() string

type FileSystem

type FileSystem struct {
	Root              string
	CreatePermissions os.FileMode
	ObjectLayout      uint
}

FileSystem allows an easy mechanism for reading and writing raw Budget related objects to and from a hard drive.

func (FileSystem) Current

func (fs FileSystem) Current(_ context.Context) (result persist.RefSpec, err error)

Current fetches the RefSpec that was most recently used to populate the index.

func (FileSystem) Fetch

func (fs FileSystem) Fetch(_ context.Context, id envelopes.ID) ([]byte, error)

Fetch is able to read into memory the marshaled form of a Budget related object.

See Also: - FileSystem.Stash

func (FileSystem) ListBranches

func (fs FileSystem) ListBranches(ctx context.Context) (<-chan string, error)

ListBranches fetches the distinct names of the branches that exist in a repository.

func (FileSystem) ReadBranch

func (fs FileSystem) ReadBranch(_ context.Context, name string) (retval envelopes.ID, err error)

ReadBranch fetches the ID that a branch is pointing at.

func (FileSystem) SetCurrent

func (fs FileSystem) SetCurrent(_ context.Context, current persist.RefSpec) error

SetCurrent replaces the current pointer to the most recent Transaction with a given RefSpec. For instance, this should be used to change which branch is currently checked-out.

func (FileSystem) Stash

func (fs FileSystem) Stash(_ context.Context, id envelopes.ID, payload []byte) error

Stash commits the provided payload to disk at a place that it can retreive again if asked for the ID specified here.

See Also: - FileSystem.Fetch

func (FileSystem) WriteBranch

func (fs FileSystem) WriteBranch(_ context.Context, name string, id envelopes.ID) error

WriteBranch sets a branch to be pointing at a particular ID.

type FilesystemBankRecordIDIndex

type FilesystemBankRecordIDIndex struct {
	Root            string
	DecoratedWriter persist.Writer
}

func (FilesystemBankRecordIDIndex) AppendBankRecordID

func (index FilesystemBankRecordIDIndex) AppendBankRecordID(bankRecordID envelopes.BankRecordID, transactionIDs ...envelopes.ID) error

AppendBankRecordID adds to the list of Transactions associated with a BankRecordID.

func (FilesystemBankRecordIDIndex) ClearBankRecordID

func (index FilesystemBankRecordIDIndex) ClearBankRecordID(bankRecordID envelopes.BankRecordID) error

ClearBankRecordID disassociates all transactions from this BankRecordID.

func (FilesystemBankRecordIDIndex) HasBankRecordId

func (index FilesystemBankRecordIDIndex) HasBankRecordId(id envelopes.BankRecordID) (bool, error)

HasBankRecordId returns true if this repository has at least one Transaction associated with a given BankRecordID.

func (FilesystemBankRecordIDIndex) WriteAccounts added in v0.5.0

func (index FilesystemBankRecordIDIndex) WriteAccounts(ctx context.Context, subject envelopes.Accounts) error

WriteAccounts passes the request along to the DecoratedWriter, if applicable. If there is no DecoratedWriter, nil is returned.

func (FilesystemBankRecordIDIndex) WriteBankRecordID

func (index FilesystemBankRecordIDIndex) WriteBankRecordID(bankRecordID envelopes.BankRecordID, transactionIDs ...envelopes.ID) error

WriteBankRecordID replaces the list of Transactions associated with a BankRecordID.

func (FilesystemBankRecordIDIndex) WriteBudget added in v0.5.0

func (index FilesystemBankRecordIDIndex) WriteBudget(ctx context.Context, subject envelopes.Budget) error

WriteBudget passes the request along to the DecoratedWriter, if applicable. If there is no DecoratedWriter, nil is returned.

func (FilesystemBankRecordIDIndex) WriteState added in v0.5.0

func (index FilesystemBankRecordIDIndex) WriteState(ctx context.Context, subject envelopes.State) error

WriteState passes the request along to the DecoratedWriter, if applicable. If there is no DecoratedWriter, nil is returned.

func (FilesystemBankRecordIDIndex) WriteTransaction added in v0.5.0

func (index FilesystemBankRecordIDIndex) WriteTransaction(ctx context.Context, subject envelopes.Transaction) error

WriteTransaction associates the given Transaction with it's BankRecordID if applicable, then passes the call along to the next Writer.

If subject does not have a BankRecordID, the association step is skipped altogether, and this continues to call the DecoratedWriter.

If DecoratedWriter is nil, the association step will still happen if applicable, but then nothing more happens.

type Repository added in v0.4.0

type Repository struct {
	FileSystem
	persist.Loader
	persist.Writer
}

func OpenRepository added in v0.4.0

func OpenRepository(ctx context.Context, loc string, options ...RepositoryOption) (*Repository, error)

OpenRepository creates a handle for interacting with an existing filesystem-based repository.

func OpenRepositoryWithCache added in v0.4.0

func OpenRepositoryWithCache(ctx context.Context, loc string, cacheSize uint, options ...RepositoryOption) (*Repository, error)

OpenRepositoryWithCache creates a handle for interacting with an existing filesystem-based repository, but includes an in-memory cache that will reduce the number of disk reads needed. The parameter cacheSize is the number of budget objects that can fit in the cache. Cache misses are read from disk.

type RepositoryConfig added in v0.4.0

type RepositoryConfig struct {
	Objects         RepositoryConfigEntry `json:"objects"`
	ObjectLocations uint                  `json:"objectLocs"`
	Branches        RepositoryConfigEntry `json:"branches"`
}

func LoadConfig added in v0.4.0

func LoadConfig(_ context.Context, loc string) (*RepositoryConfig, error)

LoadConfig reads a repository configuration file from disk.

type RepositoryConfigEntry added in v0.4.0

type RepositoryConfigEntry struct {
	Format  string `json:"format"`
	Version uint   `json:"version"`
}

type RepositoryOption added in v0.4.0

type RepositoryOption func(repository *Repository) error

func RepositoryFileMode added in v0.4.0

func RepositoryFileMode(mode os.FileMode) RepositoryOption

RepositoryFileMode creates a RepositoryOption that changes the permissions that will be used for newly created files as they are written.

func RepositoryObjectLoc added in v0.5.0

func RepositoryObjectLoc(layout uint) RepositoryOption

RepositoryObjectLoc creates a RepositoryOption that sets the layout of the object files in the filesystem.

Jump to

Keyboard shortcuts

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