Skip to content

jonathanmdr/gRPC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gRPC

Example of gRPC with Go

Compiling .proto files:


--go_out specifies out directory for generation all entities "messages of .proto file"

--go-grpc_out specifies out directory for generation all gRPC code "services of .proto file"

latest param specifies directory for get .proto file

protoc --go_out=. --go-grpc_out=. proto/course_category.proto

Installing client gRPC:


The client used for tests is named evans

# MacOS installation using brew
brew tap ktr0731/evans
brew install evans

Creating SQLite database:


# For connect on database
sqlite3 db.sqlite
-- For create table categories
create table categories(
    id string primary key,
    name string,
    description string
);

-- For create table courses
create table courses(
    id string primary key,
    name string,
    description string,
    category_id string,
    foreign key (category_id) references categories(id)
);

Running server:


go run cmd/grpcServer/main.go

Running client:


By default the evans client listens on TCP port 50051, you don't need to specify if you are using this port

evans -r repl

Select gRPC service on client:


Needs to start client before selecting gRPC service

first param is the gRPC service name

# If your function uses stream mode, for stop this use 'Ctrl + D'
service CategoryService

Calling gRPC service function on client:


Needs to start client before selecting gRPC service

first param is the function name

call CreateCategory