Example and Template about Transcoding HTTP to GRPC with Golang and Mongodb. Fyi, GRPC is modern open source high performance Remote Procedure (RPC) framework that can run in any environtment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services. gRPC is based from protocol buffer which is an input schema that will be carried out by the client or user.
In this project, I provide examples or templates about http to gRPC transcoding. Actually, gRPC itself is based on HTTP v2 but is not published. So, Google Cloud Endpoint itself supports transcoding http to grpc, more or less the schema is like this.
- GRPC
Endpoint | Description | Method |
---|---|---|
TodoService/CreateProduct | To create todo | POST |
TodoService/FindById | To get todo by id | GET |
TodoService/Update | To update todo by id | PUT |
TodoService/Delete | To delete todo by id | DELETE |
TodoService/FindAll | To sell all todo | GET |
- REST
Endpoint | Description | Method |
---|---|---|
/v1/todo | To create todo | POST |
/v1/todo/{id} | To get todo by id | GET |
/v1/todo/{id} | To update todo by id | PUT |
/v1/todo/{id} | To delete todo by id | DELETE |
/v1/todo | To sell all todo | GET |
Run this command to running download all module
go mod tidy
then running file server.go
to run the server
go run server.go
and the output will be like this
2023/08/08 14:26:20 GRPC Server running on localhost:40000
2023/08/08 14:26:20 HTTP Server running on localhost:8080
Run this command to download docker-compose (this command for linux)
sudo apt install docker-compose -y
then running this command
docker-compose up -d
and service will be running on port 40000 to GRPC
and 8080 to REST
For example schema to input in GRPC you can see in
example
folder