Example of gRPC with Go
--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
The client used for tests is named evans
# MacOS installation using brew
brew tap ktr0731/evans
brew install evans
# 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)
);
go run cmd/grpcServer/main.go
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
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
Needs to start client before selecting gRPC service
first param
is the function name
call CreateCategory