repository

package
v0.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

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

func (cfg *Config) RegisterFlags(fs *flag.FlagSet)

func (*Config) Validate

func (cfg *Config) Validate() error

Validate RepoCfg config.

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 (*MemoryRepo) CreateShelf

func (*MemoryRepo) DeleteBook

func (*MemoryRepo) DeleteShelf

func (*MemoryRepo) GetBook

func (*MemoryRepo) GetShelf

func (*MemoryRepo) ListBooks

func (*MemoryRepo) ListShelves

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

func NewMysqlRepo(db *sql.DB) (*MysqlRepo, error)

NewMysqlRepo is a factory function to generate a new repository

func (*MysqlRepo) GetShelf

type Repository

type Repository interface {
	bookstorepb.BookstoreServiceServer
}

func NewRepository

func NewRepository(cfg Config) (Repository, error)

Jump to

Keyboard shortcuts

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