Just another side project, this time it's a blog platform created using gRPC and MongoDB, all written in Go.
This documentation provides an overview of the Blog project. The project implements Create, Read, Update, and Delete (CRUD) operations for a blog service.
Before getting started, ensure that you have the following prerequisites installed on your system:
- Go (Golang)
- gRPC for Go
- MongoDB
The project has the following structure:
├── Makefile
├── blog
│ ├── client
│ │ ├── create.go
│ │ ├── delete.go
│ │ ├── list.go
│ │ ├── main.go
│ │ ├── read.go
│ │ └── update.go
│ ├── docker-compose.yml
│ ├── proto
│ │ ├── blog.pb.go
│ │ ├── blog.proto
│ │ └── blog_grpc.pb.go
│ └── server
│ ├── blog_item.go
│ ├── create.go
│ ├── delete.go
│ ├── list.go
│ ├── main.go
│ ├── read.go
│ └── update.go
├── go.mod
- proto: Contains the Protocol Buffer (protobuf) definition for the blog service.
- server: Contains the server-side code for the blog service.
- client: Contains the client-side code for interacting with the blog service.
- README.md: This documentation file.
- Makefile: This file is the real deal. It builds the go code, runs the client and the server.
The proto/blog.proto
file defines the service and messages used in the project. It specifies the following methods:
CreateBlog
: Creates a new blog post.ReadBlog
: Reads a blog post by ID.UpdateBlog
: Updates an existing blog post.DeleteBlog
: Deletes a blog post by ID.ListBlogs
: Lists all blog posts.
The server-side code is located in the server
directory. Here's an overview of the server files:
main.go
: The main server application entry point.blog_service.go
: Implements theBlogServiceServer
interface, providing the logic for the CRUD operations.
The client-side code is located in the client
directory. The client interacts with the server using gRPC. The client code provides functions to call the server's CRUD methods.
The server exposes the following gRPC API endpoints:
CreateBlog
: Creates a new blog post.ReadBlog
: Reads a blog post by ID.UpdateBlog
: Updates an existing blog post.DeleteBlog
: Deletes a blog post by ID.ListBlogs
: Lists all blog posts.
Clone the project
[email protected]:viralparmarme/go-grpc-mongodb-blog.git
Go to the project directory
cd go-grpc-mongodb-blog
Install dependencies for your backend server
go get go.mongodb.org/mongo-driver
go get google.golang.org/grpc
go get google.golang.org/protobuf
Install Docker and ensure that this command runs the MongoDB instance. Please disable any other MongoDB instance running in your system (trust me, I wasted an embarrasing number of hours trying to figure out why my Go server isn't able to establish a connection to the container running MongoDB)
docker-compose up
Build the code (ensure that make works in your system)
make blog
Start the server in one terminal window
./bin/blog/server
Start the client in a separate window
./bin/blog/client
This project is used by the following people:
Feel free to raise a pull request and adding your name to be visible here for the whole world to see!
Raise a pull request or an issue to make this project better for everyone...
For support, email [email protected] or send me a DM on Twitter.