Skip to content

第9回Go勉強会の課題@luccafort #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions grpc/ruby_client/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'grpc'
require './proto/helloworld_services_pb'
require './proto/notification_services_pb'

# 通常のレスポンス
http_client = Sample::Greeter::Stub.new(
'127.0.0.1:5502',
:this_channel_is_insecure
)

request_opts = Sample::HelloRequest.new(first_name: 'John', last_name: 'Doe')
http_response = http_client.say_hello(request_opts)
puts http_response

puts '====================='
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ファイルを分割しても良かったんですが元々Go側のコードも分割はしてなかったので1つのファイルで実行しています。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この標準出力は通常のレスポンスとStreamなレスポンスをわかりやすくする境界線として出力しているだけで特に意味はないです。


# Streamなレスポンスを受け取ったとき
stream_client = Sample::Notifier::Stub.new(
'127.0.0.1:5502',
:this_channel_is_insecure
)

request_opts = Sample::HelloRequest.new(first_name: '太郎', last_name: '兼進')
stream_request = stream_client.pereodic_hello(request_opts)
stream_request.each { |req| puts req }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今回、検証はしてないけどこの block 内で実行されているコード内で処理を抜けたい場合は条件式などで抜け出す条件を記載して return することになるのかな? 🤔
block 内で break すると意図しない挙動になるってチェリー本に書いてたのは記憶してるが詳細は忘れた。

5 changes: 3 additions & 2 deletions grpc/ruby_client/proto/helloworld_services_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions grpc/ruby_client/proto/notification_services_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.