storage

package
Version: v0.0.0-...-bc4fcfc Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// CollectionBeer identifier for JSON collection about beers
	CollectionBeer int = iota
	// CollectionReview identifier for JSON collection about reviews
	CollectionReview
)

Variables

This section is empty.

Functions

func NewStorage

func NewStorage(t Type) error

func PopulateBeers

func PopulateBeers()

PopulateBeers populates the Cellar variable with Beers

func PopulateReviews

func PopulateReviews()

PopulateReviews populates the Reviews variable with Reviews

Types

type JSONStorage

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

JSON is the data storage layered using JSON file

func NewJSONStorage

func NewJSONStorage(location string) (*JSONStorage, error)

func (*JSONStorage) FindBeer

func (s *JSONStorage) FindBeer(criteria beers.Beer) ([]*beers.Beer, error)

FindBeer locate full data set based on given criteria

func (*JSONStorage) FindBeers

func (s *JSONStorage) FindBeers() []beers.Beer

func (*JSONStorage) FindReview

func (s *JSONStorage) FindReview(criteria reviews.Review) ([]*reviews.Review, error)

FindReview locate full data set based on given criteria

func (*JSONStorage) FindReviews

func (s *JSONStorage) FindReviews() []reviews.Review

func (*JSONStorage) SaveBeer

func (s *JSONStorage) SaveBeer(beers ...beers.Beer) error

SaveBeer insert new beers

func (*JSONStorage) SaveReview

func (s *JSONStorage) SaveReview(reviews ...reviews.Review) error

SaveReview insert reviews

type MemoryStorage

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

Memory data storage layered save only in memory

func (*MemoryStorage) FindBeer

func (s *MemoryStorage) FindBeer(criteria beers.Beer) ([]*beers.Beer, error)

FindBeer locate full data set based on given criteria

func (*MemoryStorage) FindBeers

func (s *MemoryStorage) FindBeers() []beers.Beer

FindBeers return all beers

func (*MemoryStorage) FindReview

func (s *MemoryStorage) FindReview(criteria reviews.Review) ([]*reviews.Review, error)

FindReview locate full data set based on given criteria

func (*MemoryStorage) FindReviews

func (s *MemoryStorage) FindReviews() []reviews.Review

FindReviews return all reviews

func (*MemoryStorage) SaveBeer

func (s *MemoryStorage) SaveBeer(beers ...beers.Beer) error

SaveBeer insert or update beers

func (*MemoryStorage) SaveReview

func (s *MemoryStorage) SaveReview(reviews ...reviews.Review) error

SaveReview insert or update reviews

type Storage

type Storage interface {
	SaveBeer(...beers.Beer) error
	SaveReview(...reviews.Review) error
	FindBeer(beers.Beer) ([]*beers.Beer, error)
	FindReview(reviews.Review) ([]*reviews.Review, error)
	FindBeers() []beers.Beer
	FindReviews() []reviews.Review
}

Storage defines the functionality of a data store for the beer service.

var DB Storage

DB is the "global" storage instance

type Type

type Type int

Type defines available storage types

const (
	// JSON will store data in JSON files saved on disk
	JSON Type = iota
	// Memory will store data in memory
	Memory
)

Jump to

Keyboard shortcuts

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