Documentation ¶
Index ¶
- Constants
- type Config
- type MemoryConfig
- type MemoryRepo
- type MysqlConfig
- type MysqlRepo
- func (r *MysqlRepo) CreateBook(_ context.Context, _ *librarypb.CreateBookRequest) (*librarypb.Book, error)
- func (r *MysqlRepo) CreateShelf(_ context.Context, _ *librarypb.CreateShelfRequest) (*librarypb.Shelf, error)
- func (r *MysqlRepo) DeleteBook(_ context.Context, _ *librarypb.DeleteBookRequest) (*emptypb.Empty, error)
- func (r *MysqlRepo) DeleteShelf(_ context.Context, _ *librarypb.DeleteShelfRequest) (*emptypb.Empty, error)
- func (r *MysqlRepo) GetBook(_ context.Context, _ *librarypb.GetBookRequest) (*librarypb.Book, error)
- func (r *MysqlRepo) GetShelf(_ context.Context, _ *librarypb.GetShelfRequest) (*librarypb.Shelf, error)
- func (r *MysqlRepo) ListBooks(_ context.Context, _ *librarypb.ListBooksRequest) (*librarypb.ListBooksResponse, error)
- func (r *MysqlRepo) ListShelves(_ context.Context, _ *librarypb.ListShelvesRequest) (*librarypb.ListShelvesResponse, error)
- func (r *MysqlRepo) MergeShelves(_ context.Context, _ *librarypb.MergeShelvesRequest) (*librarypb.Shelf, error)
- func (r *MysqlRepo) MoveBook(_ context.Context, _ *librarypb.MoveBookRequest) (*librarypb.Book, error)
- func (r *MysqlRepo) UpdateBook(_ context.Context, _ *librarypb.UpdateBookRequest) (*librarypb.Book, error)
- type PostgresConfig
- type PostgresRepo
- func (r *PostgresRepo) CreateBook(_ context.Context, _ *librarypb.CreateBookRequest) (*librarypb.Book, error)
- func (r *PostgresRepo) CreateShelf(_ context.Context, _ *librarypb.CreateShelfRequest) (*librarypb.Shelf, error)
- func (r *PostgresRepo) DeleteBook(_ context.Context, _ *librarypb.DeleteBookRequest) (*emptypb.Empty, error)
- func (r *PostgresRepo) DeleteShelf(_ context.Context, _ *librarypb.DeleteShelfRequest) (*emptypb.Empty, error)
- func (r *PostgresRepo) GetBook(_ context.Context, _ *librarypb.GetBookRequest) (*librarypb.Book, error)
- func (r *PostgresRepo) GetShelf(_ context.Context, _ *librarypb.GetShelfRequest) (*librarypb.Shelf, error)
- func (r *PostgresRepo) ListBooks(_ context.Context, _ *librarypb.ListBooksRequest) (*librarypb.ListBooksResponse, error)
- func (r *PostgresRepo) ListShelves(_ context.Context, _ *librarypb.ListShelvesRequest) (*librarypb.ListShelvesResponse, error)
- func (r *PostgresRepo) MergeShelves(_ context.Context, _ *librarypb.MergeShelvesRequest) (*librarypb.Shelf, error)
- func (r *PostgresRepo) MoveBook(_ context.Context, _ *librarypb.MoveBookRequest) (*librarypb.Book, error)
- func (r *PostgresRepo) UpdateBook(_ context.Context, _ *librarypb.UpdateBookRequest) (*librarypb.Book, error)
- type Repository
Constants ¶
View Source
const ( BackendMemory = "memory" BackendMysql = "mysql" BackendPostgres = "postgres" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Backend string `yaml:"backend"` Memory MemoryConfig `yaml:"memory"` Mysql MysqlConfig `yaml:"mysql"` Postgres PostgresConfig `yaml:"postgres"` }
Config RepoCfg Connections config Here are each of the database connections for application.
func (*Config) RegisterFlags ¶
type MemoryConfig ¶
type MemoryConfig struct {
Enabled bool `yaml:"enabled"`
}
func (*MemoryConfig) RegisterFlags ¶
func (cfg *MemoryConfig) RegisterFlags(fs *flag.FlagSet)
func (*MemoryConfig) RegisterFlagsWithPrefix ¶
func (cfg *MemoryConfig) RegisterFlagsWithPrefix(prefix string, fs *flag.FlagSet)
func (*MemoryConfig) Validate ¶
func (cfg *MemoryConfig) Validate() error
type MemoryRepo ¶
type MemoryRepo struct { librarypb.UnimplementedLibraryServiceServer // shelves are stored in a map keyed by shelf id // books are stored in a two level map, keyed first by shelf id and then by book id Shelves map[int64]*librarypb.Shelf Books map[int64]map[int64]*librarypb.Book LastShelfID int64 // the id of the last shelf that was added LastBookID int64 // the id of the last book that was added // contains filtered or unexported fields }
MemoryRepo fulfills the Repository interface All objects are managed in an in-memory non-persistent store.
MemoryRepo is used to implement LibraryServiceServer.
func NewMemoryRepo ¶
func NewMemoryRepo(_ MemoryConfig) (*MemoryRepo, error)
NewMemoryRepo is a factory function to generate a new repository
func (*MemoryRepo) ListShelves ¶
func (mr *MemoryRepo) ListShelves(ctx context.Context, req *librarypb.ListShelvesRequest) (*librarypb.ListShelvesResponse, error)
type MysqlConfig ¶
type MysqlConfig struct { Enabled bool `yaml:"enabled"` URL string `yaml:"url"` Host string `yaml:"host"` User string `yaml:"user"` Password flagext.Secret `yaml:"password"` Schema string `yaml:"schema"` }
func (*MysqlConfig) RegisterFlags ¶
func (cfg *MysqlConfig) RegisterFlags(fs *flag.FlagSet)
func (*MysqlConfig) RegisterFlagsWithPrefix ¶
func (cfg *MysqlConfig) RegisterFlagsWithPrefix(prefix string, fs *flag.FlagSet)
func (*MysqlConfig) Validate ¶
func (cfg *MysqlConfig) Validate() error
type MysqlRepo ¶
type MysqlRepo struct {
// contains filtered or unexported fields
}
MysqlRepo is used to implement LibraryServiceServer.
func NewMysqlRepo ¶
func NewMysqlRepo(cfg MysqlConfig) (*MysqlRepo, error)
NewMysqlRepo is a factory function to generate a new repository
func (*MysqlRepo) CreateBook ¶
func (*MysqlRepo) CreateShelf ¶
func (*MysqlRepo) DeleteBook ¶
func (*MysqlRepo) DeleteShelf ¶
func (*MysqlRepo) ListBooks ¶
func (r *MysqlRepo) ListBooks(_ context.Context, _ *librarypb.ListBooksRequest) (*librarypb.ListBooksResponse, error)
func (*MysqlRepo) ListShelves ¶
func (r *MysqlRepo) ListShelves(_ context.Context, _ *librarypb.ListShelvesRequest) (*librarypb.ListShelvesResponse, error)
func (*MysqlRepo) MergeShelves ¶
func (*MysqlRepo) UpdateBook ¶
type PostgresConfig ¶
type PostgresConfig struct { Enabled bool `yaml:"enabled"` URL string `yaml:"url"` Host string `yaml:"host"` User string `yaml:"user"` Password flagext.Secret `yaml:"password"` Schema string `yaml:"schema"` }
func (*PostgresConfig) RegisterFlags ¶
func (cfg *PostgresConfig) RegisterFlags(fs *flag.FlagSet)
func (*PostgresConfig) RegisterFlagsWithPrefix ¶
func (cfg *PostgresConfig) RegisterFlagsWithPrefix(prefix string, fs *flag.FlagSet)
func (*PostgresConfig) Validate ¶
func (cfg *PostgresConfig) Validate() error
type PostgresRepo ¶
type PostgresRepo struct {
// contains filtered or unexported fields
}
func NewPostgresRepo ¶
func NewPostgresRepo(cfg PostgresConfig) (*PostgresRepo, error)
func (*PostgresRepo) CreateBook ¶
func (r *PostgresRepo) CreateBook(_ context.Context, _ *librarypb.CreateBookRequest) (*librarypb.Book, error)
func (*PostgresRepo) CreateShelf ¶
func (r *PostgresRepo) CreateShelf(_ context.Context, _ *librarypb.CreateShelfRequest) (*librarypb.Shelf, error)
func (*PostgresRepo) DeleteBook ¶
func (r *PostgresRepo) DeleteBook(_ context.Context, _ *librarypb.DeleteBookRequest) (*emptypb.Empty, error)
func (*PostgresRepo) DeleteShelf ¶
func (r *PostgresRepo) DeleteShelf(_ context.Context, _ *librarypb.DeleteShelfRequest) (*emptypb.Empty, error)
func (*PostgresRepo) GetBook ¶
func (r *PostgresRepo) GetBook(_ context.Context, _ *librarypb.GetBookRequest) (*librarypb.Book, error)
func (*PostgresRepo) GetShelf ¶
func (r *PostgresRepo) GetShelf(_ context.Context, _ *librarypb.GetShelfRequest) (*librarypb.Shelf, error)
func (*PostgresRepo) ListBooks ¶
func (r *PostgresRepo) ListBooks(_ context.Context, _ *librarypb.ListBooksRequest) (*librarypb.ListBooksResponse, error)
func (*PostgresRepo) ListShelves ¶
func (r *PostgresRepo) ListShelves(_ context.Context, _ *librarypb.ListShelvesRequest) (*librarypb.ListShelvesResponse, error)
func (*PostgresRepo) MergeShelves ¶
func (r *PostgresRepo) MergeShelves(_ context.Context, _ *librarypb.MergeShelvesRequest) (*librarypb.Shelf, error)
func (*PostgresRepo) MoveBook ¶
func (r *PostgresRepo) MoveBook(_ context.Context, _ *librarypb.MoveBookRequest) (*librarypb.Book, error)
func (*PostgresRepo) UpdateBook ¶
func (r *PostgresRepo) UpdateBook(_ context.Context, _ *librarypb.UpdateBookRequest) (*librarypb.Book, error)
type Repository ¶
type Repository interface { librarypb.LibraryServiceServer }
func NewRepository ¶
func NewRepository(cfg Config) (Repository, error)
Click to show internal directories.
Click to hide internal directories.