Created
April 25, 2017 10:21
-
-
Save MarcusLongmuir/5a704840d32e78a396956228ba102ac8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment