service

package
v0.0.0-...-76b32bc Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package service impls app services

Package service impls app services

Package service impls app services

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = errors.New("record already exists")

ErrAlreadyExists is returned when a record with the same ID already exists in the store

Functions

This section is empty.

Types

type DiskImageStore

type DiskImageStore struct {
	// contains filtered or unexported fields
}

DiskImageStore stores image on disk, and its info on memory

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 adds a new image to a laptop

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 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) *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) 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

UploadImage is a client-streaming RPC to upload a laptop image

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

Jump to

Keyboard shortcuts

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