Containerized gRPC service with a REST gateway
- Learn how to set up gRPC-gateway
- Learn how to set up branch restrictions and automated test runs
- Have a template to use for something else
protoc \
-I. \
-I $GOPATH/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis/ \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
--grpc-gateway_out=logtostderr=true:. --grpc-gateway_opt=paths=source_relative \
proto/service.proto
go run main.go grpcServer
go run main.go grpcClient --word abcdef
➜ go run main.go grpcClient --word abcdef
2022/10/19 15:49:43 echo:"abcdef" timestamp:"2022-10-19 20:49:43.293029 +0000 UTC"
go run main.go restProxy
➜ curl http://localhost:8080/echo/abcdef
{"echo":"abcdef","timestamp":"2022-10-20 22:26:46.416726 +0000 UTC"}%
Using JQ to make the response more readable
➜ curl http://localhost:8080/echo/abcdefg | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 69 100 69 0 0 5978 0 --:--:-- --:--:-- --:--:-- 69000
{
"echo": "abcdefg",
"timestamp": "2022-10-20 22:29:21.706632 +0000 UTC"
}
docker-compose up --force-recreate --remove-orphans --build
✗ curl http://localhost:8080/echo/abcdefg
{"echo":"abcdefg","timestamp":"2023-06-06 20:29:06.774947963 +0000 UTC"}%
Using JQ to make the response more readable with Docker
✗ curl http://localhost:8080/echo/abcdefg | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 72 100 72 0 0 4489 0 --:--:-- --:--:-- --:--:-- 7200
{
"echo": "abcdefg",
"timestamp": "2023-06-06 20:25:26.109105521 +0000 UTC"
}