store

package
v0.0.0-...-d171176 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package store implements a simple flat file backed persistence mechanism for storing Spring '83 boards. This store should be suitable for both clients and servers. It aims for simplicity and portability over performance or features.

On disk a board is simply a plain text file named according to the publisher's key. The first line of the file is the signature. Everything else is the content.

The store package implements a write through cache that allows read-heavy use cases (like a server, where boards are read much more frequently then they are updated) to primarily operate out of memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache map[string]s83.Board

type Store

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

func New

func New(path string) (*Store, error)

New takes a path to a directory on disk and initializes the backing data structures. In loading the directory it validates any existing boards that are found. NewStore will error if the path provided is not a directory.

func (*Store) Add

func (s *Store) Add(b s83.Board) error

Add stores a board to disk. This will clobber any existing boards. This matches the ephemeral nature of the protocol. Any errors opening or writing the backing file will be returned.

func (*Store) Count

func (s *Store) Count() int

Count returns the number of boards currently tracked by the store.

func (*Store) Get

func (s *Store) Get(key string) (s83.Board, error)

Get retrieves a board from disk based on the key. On success it returns a valid board. Otherwise it returns an appropriate error, either based on the store (e.g. the board does not exist) or based on the contents of the file (e.g. it is an invalid board, the signature fails to verify, etc).

func (*Store) Remove

func (s *Store) Remove(key string) error

Remove deletes a board from disk based on key. If the board does not exist in the store this will return an error.

Jump to

Keyboard shortcuts

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