Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active June 29, 2025 05:41
Show Gist options
  • Select an option

  • Save miguelmota/e58df24b2fff889b8d7caa13ad658b37 to your computer and use it in GitHub Desktop.

Select an option

Save miguelmota/e58df24b2fff889b8d7caa13ad658b37 to your computer and use it in GitHub Desktop.
Golang gRPC protobuf hello world example (also using grpcurl)
syntax = "proto3";
package protos;
service HelloWorld {
rpc SayHello (HelloRequest) returns (HelloResponse) {}
}
message HelloRequest {
string name = 1;
}
message HelloResponse {
string message = 1;
}
package main
import (
"log"
"net"
context "golang.org/x/net/context"
pb "github.com/user/repo/pb"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
const port = ":50051"
// Server ...
type Server struct{}
// SayHello ...
func (s *Server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloResponse, error) {
return &pb.HelloResponse{Message: "Hello, " + in.Name}, nil
}
func main() {
listen, err := net.Listen("tcp", port)
if err != nil {
log.Fatal(err)
}
grpcServer := grpc.NewServer()
pb.RegisterHelloWorldServer(grpcServer, &Server{})
reflection.Register(grpcServer)
grpcServer.Serve(listen)
}
protoc --go_out=plugins=grpc:. helloworld.proto
go run main.go
go get github.com/fullstorydev/grpcurl
go install github.com/fullstorydev/grpcurl/cmd/grpcurl
grpcurl -v -plaintext -d '{"name":"bob"}' localhost:50051 protos.HelloWorld/SayHello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment