This is a simple gRPC demonstration that shows how to use the proto-generated code with bufrnix in a project.
This example demonstrates:
- A simple gRPC server implementing a UserService
- A gRPC client that connects to the server
- Proto definitions for User management
- Use of the generated Go code from protobuf
Generate the code from the proto files:
nix run .\#packages.x86_64-linux.bufrnix generateFirst, ensure the dependencies are installed:
go mod tidygo run main.gogo run main.go -mode=servergo run main.go -mode=clientgo run main.go -mode=server -port=:50052
go run main.go -mode=client -addr=localhost:50052The service provides two RPCs:
CreateUser- Creates a new user with validationGetUser- Retrieves a user by ID
The demo showcases:
- Creating a new user with complete information
- Retrieving the created user
- Error handling for non-existent users
- Thread-safe in-memory storage
- Use of protobuf message types including enums, repeated fields, and nested messages
The proto file defines:
Usermessage with fields like id, name, email, roles, and addressesUserStatusenum (ACTIVE, INACTIVE, SUSPENDED)- Nested
Addressmessage within User - Request/Response messages for the RPCs