Skip to content

Prayag2003/grpc-proto-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gRPC Proto Go Example

This repository demonstrates how to use Protocol Buffers (.proto files) and gRPC in Go, including support for

  • Unary API
  • Server Streaming API
  • Client Streaming API
  • Bi-Directional Streaming RPC API

🚀 Prerequisites

Ensure the following tools are installed:

Install protoc using Homebrew (macOS):

brew install protoc

Verify the installation:

protoc --version

⏳ Getting Started

1️⃣ Clone the Repository

git clone https://github.com/Prayag2003/grpc-proto-go.git
cd grpc-proto-go

2️⃣ Install dependencies:

go mod tidy

⚙️ Generate Go Code from Proto

Generate the Go bindings from the proto file:

protoc --go_out=. --go-grpc_out=. proto/greet.proto

This creates:

  • proto/greet.pb.go
  • proto/greet_grpc.pb.go

▶️ Running the Example

✅ Start the Server

cd server
go run *.go

✅ Run the Client

Open a separate terminal:

cd client
go run *.go

📁 Project Structure

grpc-proto-go/
├── assets/
│   └── response.png
├── client/
│   ├── bi_stream.go
│   ├── client_stream.go
│   ├── main.go
│   ├── server_stream.go
│   └── unary.go
├── proto/
│   ├── greet_grpc.pb.go
│   ├── greet.pb.go
│   └── greet.proto
├── server/
│   ├── bi_stream.go
│   ├── client_stream.go
│   ├── main.go
│   ├── server_stream.go
│   └── unary.go
├── go.mod
├── go.sum
└── README.md

📋 Proto Definition Example

syntax = "proto3";

option go_package = "./proto";

package greet_service;

service GreetService {
    rpc SayHello(NoParam) returns (HelloResponse);
    rpc SayHelloFromServerStreaming(NamesList) returns (stream HelloResponse);
    rpc SayHelloFromClientStreaming(stream HelloRequest) returns (MessagesList);
    rpc SayHelloBidirectionalStreaming(stream HelloRequest) returns (stream HelloResponse);
}

message NoParam {}
message HelloRequest { string name = 1; }
message HelloResponse { string message = 1; }
message NamesList { repeated string names = 1; }
message MessagesList { repeated string messages = 1; }

🎯 Response

Example Response


About

Creating GRPC Server for Unary, Server Stream, Client Stream and Bidirectional Streaming

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages