storage

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

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

Go to latest
Published: Oct 5, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CollectionBeer identifier for the JSON collection of beers
	CollectionBeer = "beers"
	// CollectionReview identifier for the JSON collection of reviews
	CollectionReview = "reviews"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONBeerStorage

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

JSONBeerStorage stores beer data in JSON files

func NewJSONBeerStorage

func NewJSONBeerStorage() (*JSONBeerStorage, error)

NewJSONBeerStorage returns a new JSON beer storage

func (*JSONBeerStorage) Add

func (s *JSONBeerStorage) Add(b beers.Beer) error

Add saves the given beer to the repository

func (*JSONBeerStorage) Get

func (s *JSONBeerStorage) Get(id int) (beers.Beer, error)

Get returns a beer with the specified ID

func (*JSONBeerStorage) GetAll

func (s *JSONBeerStorage) GetAll() []beers.Beer

GetAll returns all beers

type JSONReviewStorage

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

JSONReviewStorage stores review data in JSON files

func NewJSONReviewStorage

func NewJSONReviewStorage() (*JSONReviewStorage, error)

NewJSONReviewStorage returns a new JSON reviews storage

func (*JSONReviewStorage) Add

Add saves the given review in the repository

func (*JSONReviewStorage) GetAll

func (s *JSONReviewStorage) GetAll(beerID int) []reviews.Review

GetAll returns all reviews for a given beer

type MemoryBeerStorage

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

Memory storage keeps beer data in memory

func (*MemoryBeerStorage) Add

func (m *MemoryBeerStorage) Add(b beers.Beer) error

Add saves the given beer to the repository

func (*MemoryBeerStorage) Get

func (m *MemoryBeerStorage) Get(id int) (beers.Beer, error)

Get returns a beer with the specified ID

func (*MemoryBeerStorage) GetAll

func (m *MemoryBeerStorage) GetAll() []beers.Beer

GetAll return all beers

type MemoryReviewStorage

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

Memory storage keeps review data in memory

func (*MemoryReviewStorage) Add

Add saves the given review in the repository

func (*MemoryReviewStorage) GetAll

func (m *MemoryReviewStorage) GetAll(beerID int) []reviews.Review

GetAll returns all reviews for a given beer

type Type

type Type int

StorageType defines available storage types

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

Jump to

Keyboard shortcuts

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