Golang示例代码集合
calculator
目录提供三种gRPC API类型示例,分别是:
- unary
- client streaming
- bi directional streaming
另外该示例默认开启服务端的GRPC反射服务。
[root@demo go]# evans -p 50001 -r
______
| ____|
| |__ __ __ __ _ _ __ ___
| __| \ \ / / / _. | | '_ \ / __|
| |____ \ V / | (_| | | | | | \__ \
|______| \_/ \__,_| |_| |_| |___/
more expressive universal gRPC client
[email protected]:50001> show package
+------------+
| PACKAGE |
+------------+
| calculator |
+------------+
[email protected]:50001> show service
+-------------------+---------+----------------+-----------------+
| SERVICE | RPC | REQUEST TYPE | RESPONSE TYPE |
+-------------------+---------+----------------+-----------------+
| CalculatorService | Sum | SumRequest | SumResponse |
| CalculatorService | FindMax | FindMaxRequest | FindMaxResponse |
| CalculatorService | GetMax | FindMaxRequest | FindMaxResponse |
+-------------------+---------+----------------+-----------------+
[email protected]:50001> show message
+-----------------+
| MESSAGE |
+-----------------+
| FindMaxRequest |
| FindMaxResponse |
| SumRequest |
| SumResponse |
+-----------------+
[email protected]:50001> call Sum
first_num (TYPE_INT32) => 123
second_num (TYPE_INT32) => 123
{
"sumResult": 246
}
[email protected]:50001> call GetMax
num (TYPE_INT32) => 1
num (TYPE_INT32) => {
"maxNum": 1
}
num (TYPE_INT32) => 8
num (TYPE_INT32) => {
"maxNum": 8
}
num (TYPE_INT32) => 3
num (TYPE_INT32) => 9
num (TYPE_INT32) => {
"maxNum": 9
}
num (TYPE_INT32) => 12
num (TYPE_INT32) => {
"maxNum": 12
}
num (TYPE_INT32) => 3
num (TYPE_INT32) => 14
num (TYPE_INT32) => {
"maxNum": 14
}
num (TYPE_INT32) => 12
num (TYPE_INT32) => 99
num (TYPE_INT32) => {
"maxNum": 99
}
num (TYPE_INT32) => 100
num (TYPE_INT32) => {
"maxNum": 100
}
helloworld
目录提供了gRPC SSL配置示例。
提供cgo示例代码