Documentation ¶
Index ¶
- Variables
- type DiskImageStore
- type ImageInfo
- type ImageStore
- type InMemoryLaptopStore
- type InMemoryRatingStore
- type LaptopServer
- func (server *LaptopServer) CreateLaptop(ctx context.Context, req *pb.CreateLaptopRequest) (*pb.CreateLaptopResponse, error)
- func (server *LaptopServer) RateLaptop(stream pb.LaptopService_RateLaptopServer) error
- func (server *LaptopServer) SearchLaptop(req *pb.SearchLaptopRequest, stream pb.LaptopService_SearchLaptopServer) error
- func (server *LaptopServer) UploadImage(stream pb.LaptopService_UploadImageServer) error
- type LaptopStore
- type Rating
- type RatingStore
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExists = errors.New("record already exists")
ErrAlreadyExists is returned when a record with the samer ID already exists in the store
Functions ¶
This section is empty.
Types ¶
type DiskImageStore ¶
type DiskImageStore struct {
// contains filtered or unexported fields
}
func NewDiskImageStore ¶
func NewDiskImageStore(imageFolder string) *DiskImageStore
NewDiskImageStore returns a new DiskImageStore
type ImageStore ¶
type ImageStore interface { // Save saves a new laptop image to the store Save(laptopID string, imageType string, imageData bytes.Buffer) (string, error) }
ImageStore is an interface to store laptop images
type InMemoryLaptopStore ¶
type InMemoryLaptopStore struct {
// contains filtered or unexported fields
}
InMemoryLaptopStore stores laptop in memory
func NewInMemoryLaptopStore ¶
func NewInMemoryLaptopStore() *InMemoryLaptopStore
NewInMemoryLaptopStore returns a new InMemoryLaptopStore
func (*InMemoryLaptopStore) Find ¶
func (store *InMemoryLaptopStore) Find(id string) (*pb.Laptop, error)
Find finds a laptop by id
type InMemoryRatingStore ¶
type InMemoryRatingStore struct {
// contains filtered or unexported fields
}
InMemoryRatingStore stores laptop ratings in memory
func NewInmemoryRatingStore ¶
func NewInmemoryRatingStore() *InMemoryRatingStore
NewInmemoryRatingStore returns a new InMemoryRatingStore
type LaptopServer ¶
type LaptopServer struct {
// contains filtered or unexported fields
}
LaptopServer is the server that provides laptop services
func NewLaptopServer ¶
func NewLaptopServer(laptopStore LaptopStore, imageStore ImageStore, ratingStore RatingStore) *LaptopServer
NewLaptopServer returns a new LaptopServer
func (*LaptopServer) CreateLaptop ¶
func (server *LaptopServer) CreateLaptop(ctx context.Context, req *pb.CreateLaptopRequest) (*pb.CreateLaptopResponse, error)
CreateLaptop is a unary RPC to create a new laptop
func (*LaptopServer) RateLaptop ¶
func (server *LaptopServer) RateLaptop(stream pb.LaptopService_RateLaptopServer) error
RateLaptop is a bidirectional-streaming RPC that allows client to rate a stream of laptops with a score, and returns a stream of average score for each of them
func (*LaptopServer) SearchLaptop ¶
func (server *LaptopServer) SearchLaptop(req *pb.SearchLaptopRequest, stream pb.LaptopService_SearchLaptopServer) error
SearchLaptop is a server-streaming RPC to search for laptops
func (*LaptopServer) UploadImage ¶
func (server *LaptopServer) UploadImage(stream pb.LaptopService_UploadImageServer) error
type LaptopStore ¶
type LaptopStore interface { // Save saves the laptop to the store Save(laptop *pb.Laptop) error // Find finds a laptop by ID Find(id string) (*pb.Laptop, error) // Search searches for laptops with filter, returns one by one via the found function Search(ctx context.Context, filter *pb.Filter, found func(laptop *pb.Laptop) error) error }
LaptopStore is an interface to store laptop