storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStorage

type FileStorage struct {
	Path string
	// contains filtered or unexported fields
}

func NewFileStorage

func NewFileStorage(path string) *FileStorage

func (*FileStorage) All

func (s *FileStorage) All(o Order) ([]string, error)

All returns all entries from the file.

func (*FileStorage) Append

func (s *FileStorage) Append(entry string) error

Append the entry as a new line at the end of the file.

func (*FileStorage) Close

func (s *FileStorage) Close() error

Close the file.

func (*FileStorage) Latest

func (s *FileStorage) Latest() (*string, error)

Latest returns the most recently added entry.

func (*FileStorage) Open

func (s *FileStorage) Open() error

Open the file.

func (*FileStorage) Pop

func (s *FileStorage) Pop() error

Pop removes the last line from the file.

type Order

type Order string
const (
	// OrderAsc for ascending order.
	OrderAsc Order = "ASC"

	// OrderDesc for descending order.
	OrderDesc Order = "DESC"
)

type SQLConnectionDetails

type SQLConnectionDetails struct {
	Dialect      string
	Host         string
	Port         int
	User         string
	Password     string
	DatabaseName string
	TableName    string
	SSLMode      string
}

type SQLStorage

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

func NewSQLStorage

func NewSQLStorage(scd *SQLConnectionDetails) *SQLStorage

func (*SQLStorage) All

func (s *SQLStorage) All(o Order) ([]string, error)

All returns all entries from the database.

func (*SQLStorage) Append

func (s *SQLStorage) Append(entry string) error

Append inserts a new record for that entry into the database.

func (*SQLStorage) Close

func (s *SQLStorage) Close() error

Close connection to the database.

func (*SQLStorage) Latest

func (s *SQLStorage) Latest() (*string, error)

Latest returns the most recent record (according to the migration date).

func (*SQLStorage) Open

func (s *SQLStorage) Open() error

func (*SQLStorage) Pop

func (s *SQLStorage) Pop() error

Pop deletes the most recent record (according to the migration date).

type Storage

type Storage interface {
	// Open a connection to the storage medium.
	Open() error

	// Close connection safely. This should be deferred after a call of Open.
	Close() error

	// Append (and persist) a new entry to the storage.
	Append(string) error

	// Pop removes the most recently added entry from the storage.
	Pop() error

	// All returns all items from the storage in ascending order.
	All(Order) ([]string, error)

	// Latest returns the latest/most recent item from the storage.
	Latest() (*string, error)
}

Storage represents a stack-like (i.e., simple string values in a LIFO manner) persistence management interface.

Jump to

Keyboard shortcuts

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