service

package
v0.0.0-...-abe3b89 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (*DiskImageStore) Save

func (store *DiskImageStore) Save(
	laptopID string,
	imageType string,
	imageData bytes.Buffer) (string, error)

Save saves a new laptop image to the store

type ImageInfo

type ImageInfo struct {
	LaptopID string
	Type     string
	Path     string
}

ImageInfo contains information of the laptop image

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

func (*InMemoryLaptopStore) Save

func (store *InMemoryLaptopStore) Save(laptop *pb.Laptop) error

Save saves the laptop to the store

func (*InMemoryLaptopStore) Search

func (store *InMemoryLaptopStore) Search(ctx context.Context, filter *pb.Filter, found func(laptop *pb.Laptop) error) error

Search searches for laptops with filter, returns one by one via the found function

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

func (*InMemoryRatingStore) Add

func (store *InMemoryRatingStore) Add(laptopID string, score float64) (*Rating, error)

Add adds a new laptop score to the store and returns its rating

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

type Rating

type Rating struct {
	Count uint32
	Sum   float64
}

Rating contains the rating information of a laptop

type RatingStore

type RatingStore interface {
	// Add adds a new laptop score to the store and returns its rating
	Add(laptopID string, score float64) (*Rating, error)
}

RatingStore is an interface to store laptop ratings

Jump to

Keyboard shortcuts

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