Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pb_library "../_proto/examplecom/library"
- type bookService struct{
- books []*pb_library.Book
- }
- func (s *bookService) GetBook(ctx context.Context, bookQuery *pb_library.GetBookRequest) (*pb_library.Book, error) {
- for _, book := range s.books {
- if book.Isbn == bookQuery.Isbn {
- return book, nil
- }
- }
- return nil, grpc.Errorf(codes.NotFound, "Book could not be found")
- }
- func (s *bookService) QueryBooks(bookQuery *pb_library.QueryBooksRequest, stream pb_library.BookService_QueryBooksServer) error {
- for _, book := range s.books {
- if strings.HasPrefix(s.book.Author, bookQuery.AuthorPrefix) {
- stream.Send(book)
- }
- }
- return nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement