A simple Go gRPC application that demonstrates CRUD (Create, Read, Update, Delete) operations for a User service.
go-grpc-crud/
├── proto/ # Protocol Buffers definitions
│ ├── user.proto # User service definition
│ ├── user.pb.go # Generated Go code for messages
│ └── user_grpc.pb.go # Generated Go code for service
├── server/ # Server implementation
│ ├── main.go # Server entry point
│ ├── service/ # Service implementations
│ │ └── user_service.go
│ └── store/ # Data storage
│ └── user_store.go
└── client/ # Client for testing
└── main.go # Client implementation
- Go 1.25 or later
- Protocol Buffers compiler (protoc)
- gRPC tools for Go
- Clone the repository:
git clone https://github.com/yourusername/go-grpc-crud.git
cd go-grpc-crud- Install dependencies:
go mod tidygo run server/main.goThe server will start on port 50051.
In a separate terminal:
go run client/main.goThe client will:
- Create two users
- List all users
- Get a specific user
- Update a user
- List users after update
- Delete a user
- List users after deletion
The User service provides the following operations:
- CreateUser: Create a new user with name, email, and age
- GetUser: Retrieve a user by ID
- ListUsers: List all users
- UpdateUser: Update an existing user's information
- DeleteUser: Delete a user by ID
If you make changes to the .proto files, regenerate the Go code with:
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/user.proto- The application uses an in-memory store for simplicity
- UUIDs are used for user IDs
- Basic validation is implemented for all operations
- The server includes graceful shutdown handling
Start interacting with GRPC endpoints directly from the IDE, open endpoints.http
