Here's is the link to my Medium article which explains the implementation of the code
Implementation of a simple RPC service using Golang. The RPC service can create and save blog posts.
- Client sends a request to the server to create a blog post with a given title and content.
- The server saves the blog posts created to an in-memory storage.
- The blog posts created are also saved to a JSON file named
blogs.json
in the root directory.
Directory structure
grpcblog
├── Makefile
├── README.md
├── blog
│ ├── blog.pb.go
│ ├── blog.proto
│ └── blog_grpc.pb.go
├── blogs.json
├── client
│ └── client.go
├── client.png
├── go.mod
├── go.sum
├── serializer
│ └── json.go
├── server
│ └── server.go
├── server.png
└── storage
└── storage.go
make clean
: To clean up the generated proto files
make gen
: To compile the proto file
This generates two files:
blog/blog_grpc.pb.go
blog/blog.pb.go
blog_grpc.pb.go
: contains server and client stubs.
blog.pb.go
: contains protocol buffer related code - responsible for binary serialization of data when it is transported between server and client.
Run the server and client code in two separate terminal windows:
go run server/server.go
go run client/client.go