A simple grpc+http1 service using grpc-gateway and listening on the same port.
- Go 1.16+
- Open Telemetry Collector, Tracer & metrics collector
- Docker, used for testing with testcontainer
- Buf for generating the grpc stubs
- protoc-gen-go, protoc-gen-go-grpc, ,
Default env:
SERVICE_NAME=svc-with-grpc-gateway
ADDRESS=:8080
OTLP_COLLECTOR_URL=localhost:4317
you can setup environment using .env file or environment variables (OS)
go mod tidy
After all installed properly, because this project we use opentelemetry collector (jaeger + prometheus) for tracing and metrics, so Run the otelcollector, jaeger and prometheus servers using docker-compose:
docker-compose -f deploy/docker-compose/docker-compose.yaml up
and then start:
go run cmd/server/main.go
HTTP/1.1 POST API with curl
$ curl \
--header "Content-Type: application/json" \
--data '{"name": "John"}' \
http://localhost:8080/user.v1.UserService/Create
gRPC with grpccurl
$ grpcurl \
-protoset <(buf build -o -) -plaintext \
-d '{"name": "John"}' \
localhost:8080 user.v1.UserService/Create
reponse:
{"message": "OK"}
go test ./...
openapi:
api/v1/user.swagger.json
proto :
api/v1/user.proto