Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/feliux/grpc-calculator
Simple gRPC calculator implementation with SSL, login and headers interceptors
https://github.com/feliux/grpc-calculator
grpc grpc-go
Last synced: 1 day ago
JSON representation
Simple gRPC calculator implementation with SSL, login and headers interceptors
- Host: GitHub
- URL: https://github.com/feliux/grpc-calculator
- Owner: feliux
- Created: 2024-02-17T20:16:15.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-02-17T21:01:24.000Z (11 months ago)
- Last Synced: 2024-11-15T07:32:31.717Z (2 months ago)
- Topics: grpc, grpc-go
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gRPC Calculator
Simple gRPC calculator implementation with SSL, login and headers interceptors.
**gRPC Unary**:
- `rpc Sum(SumRequest) returns (SumResponse);`
- Error Handling: `rpc Sqrt(SqrtRequest) returns (SqrtResponse);`**gRPC Server Streaming**:
- `rpc Primes(PrimesRequest) returns (stream PrimesResponse)`
**gRPC Client Streaming**:
- `rpc Average(stream AverageRequest) returns (AverageResponse)`
**gRPC Bidirectional**:
- `rpc Max(stream MaxRequest) returns (stream MaxResponse)`
## Usage
1. Install protobuf go plugins
```bash
$ go install google.golang.org/protobuf/cmd/[email protected]
$ go install google.golang.org/grpc/cmd/[email protected]
$ export PATH="$PATH:$(go env GOPATH)/bin"
```2. Compile proto files
```bash
$ cd proto
$ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative *.proto
```3. Uncomment [client/main.go](./client/main.go) with the function to test
```
//DoSum(c, &pb.SumRequest{FirstValue: 1, SecondValue: 1})
//DoSumDeadline(c, &pb.SumRequest{FirstValue: 1, SecondValue: 1}, 5*time.Second) // no error
//DoSumDeadline(c, &pb.SumRequest{FirstValue: 1, SecondValue: 1}, 1*time.Second) // timeout error
//DoPrimes(c, 400)
//DoAverage(c, []float64{1, 2, 3, 4})
//DoMax(c, []int32{1, 5, 3, 6, 2, 20})
//DoSqrt(c, -9)
```4. Generate certs
```bash
$ cd ssl
$ bash generate-certs.sh
```5. Compile server and client
```bash
$ cd ..
$ go build -o server/server server/*.go
$ go build -o client/client client/*.go
```6. Run server and client
```bash
# Run server
$ ./server/server
# Run client on another terminal
$ ./client/client
```