Skip to content

lucasdsalves/grpc-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This project is a gRPC demonstration using Go.

It shows how we can create, get and list an entity called Category.

gRPC

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.

Project technologies

Project structure

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

SQLite commands

A table Category must be created:

create table categories (id string, name string, description string);

Go Protocol Buffer Compiler

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

Running app & gRPC interaction

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.

Useful commands

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.

About

gRPC demonstration using Go

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages