Documentation ¶
Index ¶
- Constants
- type Config
- type MemoryConfig
- type MemoryRepo
- func (mr *MemoryRepo) CreateBook(_ context.Context, req *bookstorepb.CreateBookRequest) (*bookstorepb.Book, error)
- func (mr *MemoryRepo) CreateShelf(_ context.Context, req *bookstorepb.CreateShelfRequest) (*bookstorepb.Shelf, error)
- func (mr *MemoryRepo) DeleteBook(_ context.Context, req *bookstorepb.DeleteBookRequest) (*emptypb.Empty, error)
- func (mr *MemoryRepo) DeleteShelf(_ context.Context, req *bookstorepb.DeleteShelfRequest) (*emptypb.Empty, error)
- func (mr *MemoryRepo) GetBook(_ context.Context, req *bookstorepb.GetBookRequest) (*bookstorepb.Book, error)
- func (mr *MemoryRepo) GetShelf(_ context.Context, req *bookstorepb.GetShelfRequest) (*bookstorepb.Shelf, error)
- func (mr *MemoryRepo) ListBooks(_ context.Context, req *bookstorepb.ListBooksRequest) (*bookstorepb.ListBooksResponse, error)
- func (mr *MemoryRepo) ListShelves(context.Context, *emptypb.Empty) (*bookstorepb.ListShelvesResponse, error)
- type MysqlConfig
- type MysqlRepo
- type Repository
Constants ¶
View Source
const ( BackendMemory = "memory" BackendMysql = "mysql" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Backend string `yaml:"backend"` Mysql MysqlConfig `yaml:"mysql"` Memory MemoryConfig `yaml:"memory"` }
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 { bookstorepb.UnimplementedBookstoreServiceServer // 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]*bookstorepb.Shelf Books map[int64]map[int64]*bookstorepb.Book LastShelfID int64 // the id of the last shelf that was added LastBookID int64 // the id of the last book that was added Mutex sync.Mutex // global mutex to synchronize service access }
MemoryRepo fulfills the Repository interface All objects are managed in an in-memory non-persistent store.
MemoryRepo is used to implement BookstoreServiceServer.
func NewMemoryRepo ¶
func NewMemoryRepo() (*MemoryRepo, error)
NewMemoryRepo is a factory function to generate a new repository
func (*MemoryRepo) CreateBook ¶
func (mr *MemoryRepo) CreateBook(_ context.Context, req *bookstorepb.CreateBookRequest) (*bookstorepb.Book, error)
func (*MemoryRepo) CreateShelf ¶
func (mr *MemoryRepo) CreateShelf(_ context.Context, req *bookstorepb.CreateShelfRequest) (*bookstorepb.Shelf, error)
func (*MemoryRepo) DeleteBook ¶
func (mr *MemoryRepo) DeleteBook(_ context.Context, req *bookstorepb.DeleteBookRequest) (*emptypb.Empty, error)
func (*MemoryRepo) DeleteShelf ¶
func (mr *MemoryRepo) DeleteShelf(_ context.Context, req *bookstorepb.DeleteShelfRequest) (*emptypb.Empty, error)
func (*MemoryRepo) GetBook ¶
func (mr *MemoryRepo) GetBook(_ context.Context, req *bookstorepb.GetBookRequest) (*bookstorepb.Book, error)
func (*MemoryRepo) GetShelf ¶
func (mr *MemoryRepo) GetShelf(_ context.Context, req *bookstorepb.GetShelfRequest) (*bookstorepb.Shelf, error)
func (*MemoryRepo) ListBooks ¶
func (mr *MemoryRepo) ListBooks(_ context.Context, req *bookstorepb.ListBooksRequest) (*bookstorepb.ListBooksResponse, error)
func (*MemoryRepo) ListShelves ¶
func (mr *MemoryRepo) ListShelves(context.Context, *emptypb.Empty) (*bookstorepb.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 { bookstorepb.UnimplementedBookstoreServiceServer // contains filtered or unexported fields }
MysqlRepo is used to implement BookstoreServiceServer.
func NewMysqlRepo ¶
NewMysqlRepo is a factory function to generate a new repository
func (*MysqlRepo) GetShelf ¶
func (r *MysqlRepo) GetShelf(ctx context.Context, req *bookstorepb.GetShelfRequest) (*bookstorepb.Shelf, error)
type Repository ¶
type Repository interface { bookstorepb.BookstoreServiceServer }
func NewRepository ¶
func NewRepository(cfg Config) (Repository, error)
Click to show internal directories.
Click to hide internal directories.