Documentation
¶
Index ¶
- Variables
- type BookStore
- type MemBook
- func (m *MemBook) Close(_ context.Context) (err error)
- func (m *MemBook) Delete(_ context.Context, isbns []string) (err error)
- func (m *MemBook) Read(_ context.Context, isbns []string) (books map[string]models.Book, err error)
- func (m *MemBook) Write(_ context.Context, books []models.Book, operation WriteOperation) (err error)
- type MemStatus
- func (m *MemStatus) Close(_ context.Context) (err error)
- func (m *MemStatus) Delete(_ context.Context, isbns []string) (err error)
- func (m *MemStatus) Read(_ context.Context, isbns []string) (statuses map[string]models.History, err error)
- func (m *MemStatus) Write(_ context.Context, statuses map[string]models.History, ...) (err error)
- type StatusStore
- type WriteOperation
Constants ¶
This section is empty.
Variables ¶
var ( // ErrISBNExists indicates a book with the given ISBN was already in the library. ErrISBNExists = errors.New("the ISBN was already in the library") // ErrISBNNotFound indicates a book with the given ISBN was not found in the library. ErrISBNNotFound = errors.New("the ISBN was not found in the library") )
var ( // ErrNotWriteOperation indicates that the given input string was not a known write operation. ErrNotWriteOperation = errors.New("the input string was not a known write operation") )
Functions ¶
This section is empty.
Types ¶
type BookStore ¶
type BookStore interface {
// Close closes the connection to the underlying storage.
Close(ctx context.Context) (err error)
// Delete deletes the Book data for the given ISBNs. There will be no error if the ISBNs are not found.
Delete(ctx context.Context, isbns []string) (err error)
// Read reads the Book data for the given ISBNs. The error ErrISBNNotFound will be given if an ISBNs is not found.
Read(ctx context.Context, isbns []string) (books map[string]models.Book, err error)
// Write writes the given Book data. It will return ErrISBNExists for in Insert operation where the ISBN already
// exists and an ErrISBNNotFound if an Update operation has an ISBN that doesn't exist.
Write(ctx context.Context, books []models.Book, operation WriteOperation) (err error)
}
BookStore is the Book data storage interface. It allows for Book data storage operations without needing to know how the Book data are stored.
type MemBook ¶
type MemBook struct {
// contains filtered or unexported fields
}
MemBook is a BookStore implementation that stores everything in a Go map in memory.
func (*MemBook) Delete ¶
Delete deletes the Book data for the given ISBNs. There will be no error if the ISBNs are not found.
func (*MemBook) Read ¶
Read reads the Book data for the given ISBNs. The error ErrISBNNotFound will be given if an ISBNs is not found.
func (*MemBook) Write ¶
func (m *MemBook) Write(_ context.Context, books []models.Book, operation WriteOperation) (err error)
Write writes the given Book data. It will return ErrISBNExists for in Insert operation where the ISBN already exists and an ErrISBNNotFound if an Update operation has an ISBN that doesn't exist.
type MemStatus ¶
type MemStatus struct {
// contains filtered or unexported fields
}
MemStatus is a StatusStore implementation that stores everything in a Go map in memory.
func (*MemStatus) Delete ¶
Delete deletes the Status data for the ISBNs. There will be no error if the ISBNs are not found.
func (*MemStatus) Read ¶
func (m *MemStatus) Read(_ context.Context, isbns []string) (statuses map[string]models.History, err error)
Read reads the Status data for the given ISBNs. The error ErrISBNNotFound will be given if an ISBN is not found.
func (*MemStatus) Write ¶
func (m *MemStatus) Write(_ context.Context, statuses map[string]models.History, operation WriteOperation) (err error)
Write writes the given Status data. It will return ErrISBNExists for in Insert operation where the ISBN already exists and an ErrISBNNotFound if an Update operation has an ISBN that doesn't exist.
type StatusStore ¶
type StatusStore interface {
// Close closes the connection to the underlying storage.
Close(ctx context.Context) (err error)
// Delete deletes the Status data for the ISBNs. There will be no error if the ISBNs are not found.
Delete(ctx context.Context, isbns []string) (err error)
// Read reads the Status data for the given ISBNs. The error ErrISBNNotFound will be given if an ISBN is not found.
Read(ctx context.Context, isbns []string) (books map[string]models.History, err error)
// Write writes the given Status data. It will return ErrISBNExists for in Insert operation where the ISBN already
// exists and an ErrISBNNotFound if an Update operation has an ISBN that doesn't exist.
Write(ctx context.Context, statuses map[string]models.History, operation WriteOperation) (err error)
}
StatusStore is the Status data storage interface. It allows for Book data storage operations without needing to know how the Book data are stored.
func NewMemStatus ¶
func NewMemStatus() (statusStore StatusStore)
NewMemStatus creates a new MemStatus.
type WriteOperation ¶
type WriteOperation uint
WriteOperation indicates the type of write operation.
const ( // Insert indicates an insertion write operation. It will fail if the target already exists. Insert WriteOperation = iota // Update indicates an update write operation. It will fail if the target does not exist. Update // Upsert indicates an upsert write operation. It will be performed if the target exists or does not exist. Upsert )
func (WriteOperation) FromString ¶
func (w WriteOperation) FromString(s string) (operation WriteOperation, err error)
FromString will determine what write operation should take place based on the input string.