File tree Expand file tree Collapse file tree 6 files changed +115
-25
lines changed Expand file tree Collapse file tree 6 files changed +115
-25
lines changed Original file line number Diff line number Diff line change 1
- # go-grpc-basics
1
+ # WEB+DB PRESS Vol.110 特集2「[速習]gRPC」サンプルコード
2
+
3
+ 技術評論社刊「[ WEB+DB PRESS Vol.110] ( https://gihyo.jp/magazine/wdpress/archive/2019/vol110 ) 」の特集2「[速習]gRPC」のサンプルコードです。
4
+
5
+ ## 目次
6
+
7
+ 実行方法は各READMEをご覧ください。
8
+
9
+ - [ 単項RPC ── 1リクエスト/1レスポンス] ( https://github.com/vvatanabe/go-grpc-basics/tree/master/echo )
10
+ - [ サーバサイドストリーミングRPC ── 1リクエスト/多レスポンス] ( https://github.com/vvatanabe/go-grpc-basics/tree/master/downloader )
11
+ - [ クライアントサイドストリーミングRPC ── 多リクエスト/1レスポンス] ( https://github.com/vvatanabe/go-grpc-basics/tree/master/uploader )
12
+ - [ 双方向ストリーミングRPC ── 多リクエスト/多レスポンス] ( https://github.com/vvatanabe/go-grpc-basics/tree/master/chat )
13
+ - [ gRPCのインタセプタ] ( https://github.com/vvatanabe/go-grpc-basics/tree/master/interceptor )
14
+
15
+ ## 動作環境
16
+
17
+ サンプルコードは次の環境で動作確認済みです。
18
+
19
+ - Go 1.12
20
+ - grpc-go 1.19.1
21
+ - protobuf 3.7.0
22
+ - protoc-gen-go 1.3.1
23
+
24
+ ## ライセンス
25
+
26
+ サンプルコードはMITライセンスで配布しています。
27
+
28
+ http://opensource.org/licenses/mit-license.php
29
+
30
+ ## お問い合わせ
31
+
32
+ 不具合があった場合は[ 本書Webページ] ( https://gihyo.jp/magazine/wdpress/archive/2019/vol110 ) よりお問い合わせをお願いいたします。
33
+
34
+ ## ご注意
35
+
36
+ 本サンプルコード、特集の内容に基づく運用結果について、著者、ソフトウェアの開発元および提供元、株式会社技術評論社は一切の責任を負いかねますので、あらかじめご了承ください。
Original file line number Diff line number Diff line change 1
- # simple chat using bidirectional streaming RPC
1
+ # 双方向ストリーミングRPC ── 多リクエスト/多レスポンス
2
+
3
+ 双方向ストリーミングRPCを使用した、簡易的なチャット機能の例です。
4
+
5
+ ## .protoファイルをコンパイルする
2
6
3
7
```
4
- # build .proto
5
8
$ protoc -I ./chat/proto --go_out=plugins=grpc:./chat/proto/ ./chat/proto/chat.proto
9
+ ```
6
10
7
- # run server
11
+ ## gRPCサーバを起動する
12
+
13
+ ```
8
14
$ go run ./chat/server
15
+ ```
16
+
17
+ ## gRPCクライアントプログラムを実行する
9
18
10
- # run client
19
+ 引数に適当なユーザ名を与えて実行します。
20
+
21
+ ```
11
22
$ go run ./chat/client $USER_NAME
12
23
```
Original file line number Diff line number Diff line change 1
- # file downloader using server-side streaming RPC
1
+ # サーバサイドストリーミングRPC ── 1リクエスト/多レスポンス
2
+
3
+ サーバサイドストリーミングRPCを使用した、ファイルのダウンロード機能の例です。
4
+
5
+ ## .protoファイルをコンパイルする
2
6
3
7
```
4
- # build .proto
5
8
$ protoc -I ./downloader/proto --go_out=plugins=grpc:./downloader/proto/ ./downloader/proto/file.proto
9
+ ```
6
10
7
- # run server
11
+ ## gRPCサーバを起動する
12
+
13
+ ```
8
14
$ go run ./downloader/server
15
+ ```
16
+
17
+ ## gRPCクライアントプログラムを実行する
18
+
19
+ 引数にダウンロードするファイル名を与えて実行します。
9
20
10
- # run client
11
- $ go run ./downloader/client $FILE_NAME
12
21
```
22
+ $ go run ./downloader/client $FILE_NAME
23
+ ```
Original file line number Diff line number Diff line change 1
- # echo server using unary RPC
1
+ # 単項RPC ── 1リクエスト/1レスポンス
2
+
3
+ 単項RPCを使用した、クライアントからの入力をそのまま返却するEchoサーバの例です。
4
+
5
+ ## .protoファイルをコンパイルする
2
6
3
7
```
4
- # build .proto
5
8
$ protoc -I ./echo/proto --go_out=plugins=grpc:./echo/proto/ ./echo/proto/echo.proto
9
+ ```
6
10
7
- # run server
11
+ ## gRPCサーバを起動する
12
+
13
+ ```
8
14
$ go run ./echo/server
15
+ ```
16
+
17
+ ## gRPCクライアントプログラムを実行する
18
+
19
+ 引数に適当な文言を与えて実行します。
9
20
10
- # run client
11
- $ go run ./echo/client hello
12
21
```
22
+ $ go run ./echo/client hello
23
+ ```
Original file line number Diff line number Diff line change 1
- # echo server using interceptor
1
+ # gRPCのインタセプタ
2
+
3
+ インタセプタを使用した例です。
4
+
5
+ ## .protoファイルをコンパイルする
2
6
3
7
```
4
- # build .proto
5
8
$ protoc -I ./interceptor/proto --go_out=plugins=grpc:./interceptor/proto/ ./interceptor/proto/echo.proto
9
+ ```
6
10
7
- # run server
11
+ ## gRPCサーバを起動する
12
+
13
+ ```
8
14
$ go run ./interceptor/server
15
+ ```
16
+
17
+ ## gRPCクライアントプログラムを実行する
18
+
19
+ 引数に適当な文言を与えて実行します。
9
20
10
- # run client
11
- $ go run ./interceptor/client hello
12
21
```
22
+ $ go run ./interceptor/client hello
23
+ ```
Original file line number Diff line number Diff line change 1
- # file uploader using client-side streaming RPC
1
+ # クライアントサイドストリーミングRPC ── 多リクエスト/1レスポンス
2
+
3
+ クライアントサイドストリーミングRPCを使用した、ファイルのアップロード機能の例です。
4
+
5
+ ## .protoファイルをコンパイルする
2
6
3
7
```
4
- # build .proto
5
8
$ protoc -I ./uploader/proto --go_out=plugins=grpc:./uploader/proto/ ./uploader/proto/file.proto
9
+ ```
6
10
7
- # run server
11
+ ## gRPCサーバを起動する
12
+
13
+ ```
8
14
$ go run ./uploader/server
15
+ ```
16
+
17
+ ## gRPCクライアントプログラムを実行する
18
+
19
+ 引数にアップロードするファイル名を与えて実行します。
9
20
10
- # run client
11
- $ go run ./uploader/client $FILE_NAME
12
21
```
22
+ $ go run ./uploader/client $FILE_NAME
23
+ ```
You can’t perform that action at this time.
0 commit comments