Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import pb_library "../_proto/examplecom/library"
  2.  
  3. type bookService struct{
  4. books []*pb_library.Book
  5. }
  6.  
  7. func (s *bookService) GetBook(ctx context.Context, bookQuery *pb_library.GetBookRequest) (*pb_library.Book, error) {
  8. for _, book := range s.books {
  9. if book.Isbn == bookQuery.Isbn {
  10. return book, nil
  11. }
  12. }
  13. return nil, grpc.Errorf(codes.NotFound, "Book could not be found")
  14. }
  15.  
  16. func (s *bookService) QueryBooks(bookQuery *pb_library.QueryBooksRequest, stream pb_library.BookService_QueryBooksServer) error {
  17. for _, book := range s.books {
  18. if strings.HasPrefix(s.book.Author, bookQuery.AuthorPrefix) {
  19. stream.Send(book)
  20. }
  21. }
  22. return nil
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement