Set up gRPC server and client in Go
✓Works with OpenClaudeYou are a Go backend developer. The user wants to set up a working gRPC server and client in Go with protocol buffers.
What to check first
- Run
go versionto confirm Go 1.13+ is installed - Verify
protocis installed:protoc --version(if not, install from https://github.com/protocolbuffers/protobuf/releases) - Run
go install google.golang.org/protobuf/cmd/protoc-gen-go@latestandgo install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latestto get Go code generators
Steps
- Create a
proto/directory and write a.protofile defining your service messages and RPC methods usingsyntax = "proto3" - Generate Go code from
.protofile usingprotoc --go_out=. --go-grpc_out=. proto/your_service.proto - Import
"google.golang.org/grpc"and create a server struct that implements the generated service interface - Implement each RPC method defined in your proto file on the server struct, matching the exact signature from generated code
- In main, create a TCP listener with
net.Listen("tcp", ":port")and register your service withgrpc.NewServer()thenRegisterYourServiceServer() - Call
server.Serve(listener)to start the server blocking on that port - For the client, use
grpc.Dial(":port", grpc.WithInsecure())to connect and create a client stub with the generated constructor - Call RPC methods on the stub with a context timeout using
context.WithTimeout(context.Background(), 5*time.Second)
Code
// proto/greeter.proto
syntax = "proto3";
package helloworld;
option go_package = "github.com/example/greeter/gen/helloworld";
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
// server.go
package main
import (
"context"
"fmt"
"log"
"net"
"google.golang.org/grpc"
pb "github.com/example/greeter/gen/helloworld"
)
type server struct {
pb.UnimplementedGreeterServer
}
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
return &pb.HelloReply{Message: fmt.Sprintf("Hello, %s!", in.Name)}, nil
}
func main() {
lis, err := net.Listen("tcp", ":50051")
if err !=
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Go Skills
Other Claude Code skills in the same category — free to download.
Go API Setup
Scaffold Go REST API with Gin or Chi router
Go Testing
Set up Go testing with table-driven tests and mocks
Go Modules
Manage Go modules and dependency versioning
Go Concurrency
Implement goroutines, channels, and concurrency patterns
Go Docker
Create optimized multi-stage Docker build for Go apps
Go Middleware
Create HTTP middleware chain in Go
Go CLI
Build CLI applications with Cobra in Go
Want a Go skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.