This project demonstrates a basic gRPC CRUD application with Swagger documentation. It includes both gRPC server and client implementations as well as an HTTP server with Swagger integration for API documentation
- main.go: Entry point for the application.
- server/: Contains the server-side code.
- server.go: Initializes and starts the gRPC server.
- user-service.go: Implements the user service with CRUD operations.
- handler.go: Contains request handlers.
- proto/: Contains the protobuf definitions.
- user.proto: Protobuf definition file for the user service.
- docs/: Contains the Swagger documentation.
- json.docs: Swagger JSON documentation file.
- client/: Contains the client-side code.
- client.go: Implements a gRPC client to interact with the server.
- Go 1.16+
- PostgreSQL
- Swagger (for generating documentation)
-
Clone the repository:
git clone https://github.com/your-repo/swag-grpc-crud.git cd swag-grpc-crud
-
Install dependencies:
go mod tidy
-
Set up PostgreSQL database:
- Create a database and update the connection string in
server/server.go
.
- Create a database and update the connection string in
-
Generate gRPC code from proto file:
protoc --go_out=. --go-grpc_out=. proto/user.proto
-
Generate Swagger documentation:
swag init
Start the gRPC and HTTP servers:
go run main.go
You can test the gRPC server using the client provided in client/client.go or any gRPC client of your choice.
Once the HTTP server is running, access the Swagger UI at http://localhost:8080/swagger/index.html to see the API documentation and test the endpoints.
This project showcases a complete implementation of a gRPC-based CRUD application, enhanced with Swagger for API documentation. By following the provided structure and setup instructions, you can easily start both gRPC and HTTP servers, connect to a PostgreSQL database, and interact with the API using a gRPC client or Swagger UI. The project structure is modular, making it easy to extend or modify as needed for other types of gRPC services or additional features. This setup ensures that you have a robust and well-documented foundation for building scalable microservices with gRPC and Go.
This app was made with 💖 by Hamza under the guidance of Sir Husnain.