A simple gRPC-based job management service built with Go and Protocol Buffers. This project demonstrates a basic CRUD API for managing job records using gRPC.
grpc-jobs/
├── cmd/
│ ├── client/ # gRPC client implementation
│ └── server/ # gRPC server implementation
├── protos/ # Protocol Buffer definitions and generated code
│ ├── jobs.proto # Service and message definitions
│ ├── jobs.pb.go # Generated Go structs
│ └── jobs_grpc.pb.go # Generated gRPC client/server code
└── .vscode/ # VS Code debug configuration
The service provides the following gRPC methods:
- CreateJob: Create a new job with name, description, and status
- GetJob: Retrieve a specific job by ID
- GetJobs: Stream all jobs with optional limit (server streaming)
- DeleteJob: Remove a job by ID
The service is defined in protos/jobs.proto with the following key message types:
JobCreateRequest: Contains job_name, job_description, and statusJobRequest: Contains job_id for lookup operationsJobResponse: Full job details including auto-generated job_idJobListOptions: Options for listing jobs (limit parameter)
- Go 1.19 or later
- Protocol Buffers compiler (protoc)
- gRPC Go plugins
go run cmd/server/main.goThe server will start listening on port 50051.
go run cmd/client/main.goThe client demonstrates creating a job, retrieving it, listing jobs, and deleting it.
The server (cmd/server/main.go) implements the JobsServer interface with:
- In-memory job storage using a map
- Thread-safe operations with
sync.RWMutex - UUID generation for job IDs using
github.com/google/uuid - Proper gRPC error handling with status codes
The client (cmd/client/main.go) demonstrates:
- Creating a gRPC connection with
grpc.NewClient - Using the generated
JobsClientfor method calls - Handling streaming responses for the GetJobs method
- Context-based request timeouts
VS Code launch configurations are provided in .vscode/launch.json for debugging both client and server.
If you modify protos/jobs.proto, regenerate the Go code with:
protoc --go_out=. --go-grpc_out=. protos/jobs.protogoogle.golang.org/grpc- gRPC Go implementationgoogle.golang.org/protobuf- Protocol Buffers runtimegithub.com/google/uuid- UUID generation
The service implements proper gRPC status codes:
InvalidArgumentfor missing required fieldsNotFoundfor non-existent job IDsUnimplementedfor unsupported operations (viaUnimplementedJobsServer)