This is the documentation for my Golang gRPC project.
This project is part of my learning process of golang and gRPC.
To understand microservices
.
Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
Official documentation: https://developers.google.com/protocol-buffers
gRPC is a modern, open source, high-performance remote procedure call (RPC) framework
Official documentation: https://grpc.io/docs/
# Linux
apt install -y protobuf-compiler
protoc --version
# Or MacOS
brew install protobuf
protoc --version
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go get google.golang.org/protobuf
go get google.golang.org/grpc
go get github.com/lib/pq
Here are two different ways to compile the proto file to golang code
This command will generate the golang code for the proto file,
example: student.pb.go
and student_grpc.pb.go
in the proto folder or test.pb.go
and test_grpc.pb.go
in the proto folder
Student proto file: studentpb/student.studentpb
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative studentpb/student.proto
Test proto file: testpb/test.testpb
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative testpb/test.proto
Or you can run this script to compile all the proto files in the proto folder
./compile-proto-files.sh studentpb/student.proto testpb/test.proto
--go_out
is the output path for the generated golang code--go_opt
is the option for the generated golang code--go-grpc_out
is the output path for the generated golang code--go-grpc_opt
is the option for the generated golang codename/name.proto
is the path to the proto file
cd database
docker build -t github-thrashy-grpc .
docker run -d -p 54321:5432 --name postgres-grpc github-thrashy-grpc
go run server-student/main.go