This project is a gRPC demonstration using Go.
It shows how we can create, get and list an entity called Category.
gRPC is a Remote Procedure Call (RPC) framework developed by Google that makes the communication process between systems very smooth and fast using proto buffers and HTTP2.
It can be very useful in multiple scenarios, including microservices.
In the opposite of REST, gRPC supports bidirecional communication and streams, where we can send and receive data simultaneously.
- Go
- Go Protocol Buffer Compiler
- Evans - gRPC client
- SQLite
cmd - main package
internal
| database - services responsible to interact with database
| pb - auto-generated by protoc-gen-go-grpc lib
| services - methods responsible to interact with proto, rpc and stream
proto - proto file
db.sqlite - in memory relational database
A table Category must be created:
create table categories (id string, name string, description string);
If you're using Windows and have Chocolatey as package manager, you can install Go Protocol Buffer Compiler using the command below
choco install protoc
You'll need to have two terminals opened.
One to run the project
go run .\cmd\grpcServer\main.go
And the other one to run Evans, the gRPC client
evans -r repl
- Inside Evans, you'll be able to see the list of calls available
- Calling 'ListCategories'
- Calling 'CreateCategoryStreamBidirectional'
That's the gRPC magic!
On this call, we'll be sending and receiving data simultaneously.
To initiate a project
go mod init projectName
To run the project
go run .\cmd\grpcServer\main.go
Command that synchronizes the go mod file with the actual dependencies used in the codebase
go mod tidy
Running SQLIte (it depends on SQLite is installed and configured on your OS). I used command below on Windows.
C:\sqlite\sqlite3.exe db.sqlite
This project was built and inspired during course on the Fullcycle platform.