Skip to content

1412335/grpc-rest-microservice

Repository files navigation

GRPC Rest Microservice

Install

make install

# protoc
https://github.com/protocolbuffers/protobuf/releases

# protoc go
go get -u github.com/golang/protobuf/protoc-gen-go

# grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

# grpc-gateway with swagger
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

# grpc-web
https://github.com/grpc/grpc-web/releases

# install deps into vendor dir
go mod vendor

Gen proto

Using protoc

make gen

Using namely/gen-grpc-gateway

On Linux/Mac

make gen-gateway-unix

On Windows (with powershell)

cd ./api/proto/v2

docker run --rm --name protoc-gen -v ${pwd}:/defs namely/gen-grpc-gateway \
    -f . -s ServiceA \
    -o ..\..\..\pkg\api\v2\gen\grpc-gateway

Gen OpenAPI with statik

make gen-openapi

Running

All

make grpc

Internal grpc

# start grpc service
docker-compose up -d --build v2

# run grpc client
docker-compose up -d --build v2-client

grpc-gateway

# simple testing locally (only unary request)
make v2curl

grpc-web

# grpc service + envoy proxy
make grpc-web

# grpc js client
make grpc-web-client

# testing
curl -X GET localhost:8081

Cli with evans

# v1
make cli
# v2
make v2cli

Jaeger UI

OpenAPI SwaggerUI

Note

  • Copy & paste /include/google into protobuf folder (eg: ./api/proto/v2)

Docs

Overall

Gogo protobuf

Official examples

External examples

Others