Skip to content

Dev-HyunSang/grpc-go-course

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang-grpc

Go언어와 gRPC를 사용하며, gRPC [Golang] Master Class: Build Modern API & Microservices를 보면서 Go언어에서 gRPC를 사용하는 방법을 익힙니다.

Installation

gRPC

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin 
$ brew install protoc-gen-go
$ brew tap yoheimuta/protolint
$ brew install protolint
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

Generate gRPC

$ protoc -Igreet/proto --go_out=. --go_opt=module=github.com/dev-hyunsang/grpc-go-course --go-grpc_out=. --go-grpc_opt=module=github.com/dev-hyunsang/grpc-go-course greet/proto/dummy.proto

Using Evans

Installation

$ brew tap ktr0731/evans
$ brew install evans

Command in gRPC

> pacakge calculator
> show message
+---------------+
|    MESSAGE    |
+---------------+
| AvgRequest    |
| AvgResponse   |
| MaxRequest    |
| MaxResponse   |
| PrimeRequest  |
| PrimeResponse |
| SqrtRequest   |
| SqrtResponse  |
| SumRequest    |
| SumResponse   |
+---------------+
> show service
+-------------------+--------+--------------+---------------+
|      SERVICE      |  RPC   | REQUEST TYPE | RESPONSE TYPE |
+-------------------+--------+--------------+---------------+
| CalculatorService | Sum    | SumRequest   | SumResponse   |
| CalculatorService | Primes | PrimeRequest | PrimeResponse |
| CalculatorService | Avg    | AvgRequest   | AvgResponse   |
| CalculatorService | Max    | MaxRequest   | MaxResponse   |
| CalculatorService | Sqrt   | SqrtRequest  | SqrtResponse  |
+-------------------+--------+--------------+---------------+

> service CalculatorService
> call Sum
first_number (TYPE_INT32) => 1
second_number (TYPE_INT32) => 1
{
  "result": 2
}
> call Primes
number (TYPE_INT64) => 42
{
  "result": "2"
}
{
  "result": "3"
}
{
  "result": "7"
}

> call Avg
number (TYPE_INT32) => 1
number (TYPE_INT32) => 2
number (TYPE_INT32) => 3
number (TYPE_INT32) => 4
number (TYPE_INT32) => 5
number (TYPE_INT32) => 6
number (TYPE_INT32) => 7
number (TYPE_INT32) => 8
number (TYPE_INT32) => 9
number (TYPE_INT32) => 10
number (TYPE_INT32) => 
{
  "result": 5.5
}

참고한 글 및 문서

About

gRPC [Golang] Master Class: Build Modern API & Microservices를 보며 gRPC에 대해 공부합니다.

Topics

Resources

Stars

Watchers

Forks