|
| 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 | +``` |
0 commit comments