storage

package
v0.0.0-...-d65b73d Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorUnknownStorageType is the error returned when trying to instantiate a storage of unknown type
	ErrorUnknownStorageType = errors.New("unknown storage type")
	// ErrorNotFound is the error returned when trying to find a post by non-existent path
	ErrorNotFound = errors.New("record not found")
)

Functions

This section is empty.

Types

type BoltDBStorage

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

BoltDBStorage is the Storage implementation on top of BoltDB

func NewBoltDBStorage

func NewBoltDBStorage(path string, postsPerPage int) (*BoltDBStorage, error)

NewBoltDBStorage creates new BoltDBStorage instance

func (*BoltDBStorage) Close

func (s *BoltDBStorage) Close() error

Close closes the storage and frees all resources

func (*BoltDBStorage) Finalize

func (s *BoltDBStorage) Finalize() error

Finalize is called after all posts are persisted in the storage

func (*BoltDBStorage) FindByPath

func (s *BoltDBStorage) FindByPath(path string) (*model.Post, error)

FindByPath searches for a post by path

func (*BoltDBStorage) ListAll

func (s *BoltDBStorage) ListAll(page int) ([]*model.Post, error)

ListAll returns ordered by date posts page

func (*BoltDBStorage) ListTag

func (s *BoltDBStorage) ListTag(tag string, page int) ([]*model.Post, error)

ListTag returns ordered by date posts page for a tag

func (*BoltDBStorage) Meta

func (s *BoltDBStorage) Meta() *model.Meta

Meta returns metadata for all persisted posts

func (*BoltDBStorage) Save

func (s *BoltDBStorage) Save(post *model.Post) error

Save persists new post in the storage

func (*BoltDBStorage) TagMeta

func (s *BoltDBStorage) TagMeta(tag string) *model.Meta

TagMeta returns metadata for all persisted posts for a tag

type MemoryStorage

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

MemoryStorage is the in memory Storage implementation

func NewMemoryStorage

func NewMemoryStorage(postsPerPage int) (*MemoryStorage, error)

NewMemoryStorage creates new MemoryStorage instance

func (*MemoryStorage) Close

func (s *MemoryStorage) Close() error

Close closes the storage and frees all resources

func (*MemoryStorage) Finalize

func (s *MemoryStorage) Finalize() error

Finalize is called after all posts are persisted in the storage

func (*MemoryStorage) FindByPath

func (s *MemoryStorage) FindByPath(path string) (*model.Post, error)

FindByPath searches for a post by path

func (*MemoryStorage) ListAll

func (s *MemoryStorage) ListAll(page int) ([]*model.Post, error)

ListAll returns ordered by date posts page

func (*MemoryStorage) ListTag

func (s *MemoryStorage) ListTag(tag string, page int) ([]*model.Post, error)

ListTag returns ordered by date posts page for a tag

func (*MemoryStorage) Meta

func (s *MemoryStorage) Meta() *model.Meta

Meta returns metadata for all persisted posts

func (*MemoryStorage) Save

func (s *MemoryStorage) Save(post *model.Post) error

Save persists new post in the storage

func (*MemoryStorage) TagMeta

func (s *MemoryStorage) TagMeta(tag string) *model.Meta

TagMeta returns metadata for all persisted posts for a tag

type Storage

type Storage interface {
	io.Closer

	// Save persists new post in the storage
	Save(post *model.Post) error
	// Finalize is called after all posts are persisted in the storage
	Finalize() error
	// FindByPath searches for a post by path
	FindByPath(path string) (*model.Post, error)
	// ListAll returns ordered by date posts page
	ListAll(page int) ([]*model.Post, error)
	// ListTag returns ordered by date posts page for a tag
	ListTag(tag string, page int) ([]*model.Post, error)

	// Meta returns metadata for all persisted posts
	Meta() *model.Meta
	// TagMeta returns metadata for all persisted posts for a tag
	TagMeta(tag string) *model.Meta
}

Storage is the interface for posts storage

func NewStorage

func NewStorage(dsn string, postsPerPage int) (Storage, error)

NewStorage returns new storage instance by type

Jump to

Keyboard shortcuts

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