Skip to content

Commit f2c15ef

Browse files
authored
feat: add multi proto grpc app (#188)
* feat: add multi proto grpc app Signed-off-by: gouravkrosx <gouravgreatkr@gmail.com> * fix: path Signed-off-by: gouravkrosx <gouravgreatkr@gmail.com> --------- Signed-off-by: gouravkrosx <gouravgreatkr@gmail.com>
1 parent 34cc76d commit f2c15ef

20 files changed

Lines changed: 2353 additions & 0 deletions

File tree

grpc-apps/multi-proto/README.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Multi-Proto gRPC Application
2+
3+
A gRPC server application demonstrating multiple protocol buffer files with complex data types including strings, integers, booleans, nested objects, maps, repeated fields, and timestamp usage.
4+
5+
## Purpose
6+
7+
This sample app helps Keploy verify whether the Protoscope-to-JSON feature is functioning correctly.
8+
9+
## Prerequisites
10+
11+
Before you begin, ensure you have Go installed on your system.
12+
13+
## Generate Go Files from Proto Definitions
14+
15+
### 1. Install Required Tools
16+
17+
Install the Protocol Buffer compiler and Go plugins:
18+
19+
```bash
20+
# Install protoc-gen-go
21+
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
22+
23+
# Install protoc-gen-go-grpc
24+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
25+
26+
# Ensure the protoc compiler is installed
27+
# For macOS:
28+
brew install protobuf
29+
30+
# For Linux (Ubuntu/Debian):
31+
sudo apt update
32+
sudo apt install -y protobuf-compiler
33+
```
34+
35+
Make sure `$GOPATH/bin` is in your PATH:
36+
37+
```bash
38+
export PATH="$PATH:$(go env GOPATH)/bin"
39+
```
40+
41+
### 2. Generate Go Code
42+
43+
Navigate to the protos directory and run the generation script:
44+
45+
```bash
46+
cd protos
47+
chmod +x generate.sh
48+
./generate.sh
49+
```
50+
51+
This will generate Go code for all proto files in the `svc/v1` directory.
52+
53+
## Install grpcurl
54+
55+
grpcurl is a command-line tool for interacting with gRPC servers.
56+
57+
### Installation
58+
59+
```bash
60+
# Install grpcurl using Go
61+
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
62+
```
63+
64+
### Set PATH
65+
66+
Ensure `grpcurl` is in your PATH:
67+
68+
```bash
69+
# Add this to your ~/.bashrc, ~/.zshrc, or equivalent
70+
export PATH="$PATH:$(go env GOPATH)/bin"
71+
72+
# Reload your shell configuration
73+
source ~/.bashrc # or source ~/.zshrc
74+
```
75+
76+
Verify installation:
77+
78+
```bash
79+
grpcurl --version
80+
```
81+
82+
## Run the Application
83+
84+
### 1. Install Dependencies
85+
86+
Navigate to the server directory and install dependencies:
87+
88+
```bash
89+
cd server
90+
go mod tidy
91+
```
92+
93+
### 2. Start the Server
94+
95+
```bash
96+
go run main.go
97+
```
98+
99+
The server will start listening on port `50051`.
100+
101+
## Test with grpcurl
102+
103+
### GetSimpleData API
104+
105+
```bash
106+
grpcurl -plaintext -d '{"id": "123"}' localhost:50051 svc.v1.DataService/GetSimpleData
107+
```
108+
109+
Expected response:
110+
```json
111+
{
112+
"message": "Simple data retrieved successfully",
113+
"code": 200,
114+
"success": true,
115+
"value": 123.45,
116+
"items": ["item1", "item2", "item3"],
117+
"metadata": {
118+
"key1": "value1",
119+
"key2": "value2"
120+
},
121+
"timestamp": "2025-11-26T..."
122+
}
123+
```
124+
125+
### GetComplexData API
126+
127+
```bash
128+
grpcurl -plaintext -d '{"query": "test", "limit": 10}' localhost:50051 svc.v1.DataService/GetComplexData
129+
```
130+
131+
Expected response includes users, products, statistics, and metadata with timestamps.
132+
133+
## List Available Services
134+
135+
To see all available services and methods:
136+
137+
```bash
138+
grpcurl -plaintext localhost:50051 list
139+
grpcurl -plaintext localhost:50051 list svc.v1.DataService
140+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
echo "Generating Go code from proto files..."
7+
8+
# Generate Go code for svc/v1 proto files
9+
# -I. includes the current directory (protos/)
10+
# -I../third_party includes the third_party directory at multi-proto root
11+
protoc --go_out=. --go_opt=paths=source_relative \
12+
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
13+
-I. \
14+
-I../third_party \
15+
svc/v1/*.proto
16+
17+
echo "✓ Proto files generated successfully!"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module github.com/keploy/samples-go/grpc-apps/multi-proto/protos
2+
3+
go 1.21
4+
5+
require (
6+
google.golang.org/grpc v1.59.0
7+
google.golang.org/protobuf v1.31.0
8+
)
9+
10+
require (
11+
github.com/golang/protobuf v1.5.3 // indirect
12+
golang.org/x/net v0.18.0 // indirect
13+
golang.org/x/sys v0.14.0 // indirect
14+
golang.org/x/text v0.14.0 // indirect
15+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
16+
)

0 commit comments

Comments
 (0)