storage

package
v0.0.0-...-6c27aa2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	config.Config
}

Config encapsulates config.StorageConfig, so that we can define methods on it in this package

func (*Config) NewMemStore

func (*Config) NewMemStore() (Storage, error)

NewMemStore creates a new empty MemStore

func (*Config) NewMongoStore

func (c *Config) NewMongoStore() (Storage, error)

NewMongoStore creates a new mongodb client, based on the config passed in

func (*Config) ProcessStorageConfig

func (c *Config) ProcessStorageConfig(storageConfig interface{}) error

ProcessStorageConfig parses environment variables to a particular storage config interface we use the prefix <appname>_<storagekind> e.g. RANDFLIX_MONGOSTORE storageConfig must be a pointer to a struct

type MemStore

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

MemStore is in-memory storage

func (*MemStore) AddTitle

func (m *MemStore) AddTitle(t *title.Title) (*title.Title, error)

AddTitle adds the title to storage

func (*MemStore) Disconnect

func (m *MemStore) Disconnect()

Disconnect disconnects from storage (in this case it does nothing)

func (*MemStore) GetTitle

func (m *MemStore) GetTitle(id string) (*title.Title, error)

GetTitle retrieves a title from storage by id

func (*MemStore) ListTitles

func (m *MemStore) ListTitles(pageSize int, page int) ([]*title.Title, error)

ListTitles retrieves all titles from storage, given the pageSize and page note: page is zero indexed

func (*MemStore) RandomTitle

func (m *MemStore) RandomTitle(filters ...title.Filter) (*title.Title, error)

RandomTitle chooese a random title from storage (filtered by the filters)

func (*MemStore) UpdateTitle

func (m *MemStore) UpdateTitle(t *title.Title) (*title.Title, error)

UpdateTitle replaces the title in storage

type MongoStore

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

MongoStore is storage using mongodb

func (*MongoStore) AddTitle

func (m *MongoStore) AddTitle(t *title.Title) (*title.Title, error)

AddTitle adds the title passed in

func (*MongoStore) Disconnect

func (m *MongoStore) Disconnect()

Disconnect disconnects from the mongodb

func (*MongoStore) GetTitle

func (m *MongoStore) GetTitle(id string) (*title.Title, error)

GetTitle gets a single title by id, if it doesn't exist, it returns nil

func (*MongoStore) ListTitles

func (m *MongoStore) ListTitles(pageSize int, page int) ([]*title.Title, error)

ListTitles lists all elements in the mongo store, by page and pageSize

func (*MongoStore) RandomTitle

func (m *MongoStore) RandomTitle(titleFilters ...title.Filter) (*title.Title, error)

RandomTitle picks a random title based on the filters passed in

func (*MongoStore) UpdateTitle

func (m *MongoStore) UpdateTitle(t *title.Title) (*title.Title, error)

UpdateTitle updates the title passed in

type Storage

type Storage interface {
	// Disconnect disconnects from the storage
	Disconnect()
	// RandomTitle gets a random title from storage
	RandomTitle(filters ...title.Filter) (*title.Title, error)
	// AddTitle adds a title to storage
	AddTitle(t *title.Title) (*title.Title, error)
	// UpdateTitle replaces a title in storage
	UpdateTitle(t *title.Title) (*title.Title, error)
	// GetTitle retrieves a title from storage by id
	GetTitle(id string) (*title.Title, error)
	// ListTitles retrieves all titles from storage
	ListTitles(pageSize int, page int) ([]*title.Title, error)
}

Storage provides storage functions for the api

func CreateStorage

func CreateStorage(config *config.Config) (Storage, error)

CreateStorage is a factory method to create storage of any type, based on the config

Jump to

Keyboard shortcuts

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