Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 1017 Bytes

README.md

File metadata and controls

55 lines (37 loc) · 1017 Bytes

gRPC Example

This guide gets you started with gRPC in Go with a simple working example.

Prerequisites

Install the protocol compiler plugins for Go using the following commands:

go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]

Update your PATH so that the protoc compiler can find the plugins:

export PATH="$PATH:$(go env GOPATH)/bin"

Regenerate gRPC code

protoc --go_out=gen --go_opt=paths=source_relative \
  --go-grpc_out=gen --go-grpc_opt=paths=source_relative \
  -I=$PWD pb/helloworld.proto

Runing

First Step: run grpc server

go run grpc/server.go

Second Step: run gin server

go run gin/main.go

Testing

Send data to gin server:

curl -v 'http://localhost:8080/rest/n/gin'

or using grpcurl command:

grpcurl -d '{"name": "gin"}' \
  -plaintext localhost:50051 helloworld.v1.Greeter/SayHello