Skip to content

Instantly share code, notes, and snippets.

@MarcusLongmuir
Created April 25, 2017 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcusLongmuir/5a704840d32e78a396956228ba102ac8 to your computer and use it in GitHub Desktop.
Save MarcusLongmuir/5a704840d32e78a396956228ba102ac8 to your computer and use it in GitHub Desktop.
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