Documentation
¶
Overview ¶
Package repository provides access to the books data used by the site.
The books repository is responsible for loading the books view model from storage. In this service the default implementation reads a YAML file from an embedded filesystem and decodes it into the books model.
This package is designed to be wired via dependency injection (see Module in this package). Most callers should depend only on the Repository interface.
Public API ¶
- Repository defines the interface used by controllers to fetch books.
- NewRepository constructs the default repository implementation.
The concrete implementation type (for example FileSystemRepository) is exported only for completeness and should generally not be referenced directly by consumers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Module = di.Module( di.Constructor(NewRepository), )
Module for fx.
Functions ¶
This section is empty.
Types ¶
type FileSystemRepository ¶
type FileSystemRepository struct {
// contains filtered or unexported fields
}
FileSystemRepository is a Repository backed by an `fs.FS` containing a YAML file.
func (*FileSystemRepository) GetBooks ¶
func (r *FileSystemRepository) GetBooks() *model.Books
GetBooks loads, decodes, and returns the books view model.
The books are read from `books/repository/books.yaml`, decoded as YAML, sorted by Title, and enriched with the repository's meta Info.
This method panics if the YAML file cannot be read or decoded (via `runtime.Must`).
type Repository ¶
type Repository interface {
// GetBooks returns the books view model loaded from the underlying storage.
GetBooks() *model.Books
}
Repository provides access to the books data used by the site.
Implementations return a fully-populated books view model (including shared meta information) suitable for rendering by the MVC layer.
func NewRepository ¶
NewRepository constructs the default books Repository implementation.
The default implementation reads books data from a YAML file in the provided filesystem, decodes it with the provided YAML encoder, and annotates the resulting model with the provided meta Info.