Skip to content

Golang示例代码集合(分布式锁/SSO/gRPC等)

Notifications You must be signed in to change notification settings

b43646/golang_code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang_code

Golang示例代码集合

Image of Yaktocat

gRPC

calculator 目录提供三种gRPC API类型示例,分别是:

  • unary
  • client streaming
  • bi directional streaming

Image of Yaktocat

另外该示例默认开启服务端的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

提供cgo示例代码

About

Golang示例代码集合(分布式锁/SSO/gRPC等)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published