https://github.com/radutopala/grpc-calculator
A gRPC protobuf expressions calculator
https://github.com/radutopala/grpc-calculator
go golang grpc grpc-gateway grpc-go grpc-server k8s protobuf
Last synced: about 2 months ago
JSON representation
A gRPC protobuf expressions calculator
- Host: GitHub
- URL: https://github.com/radutopala/grpc-calculator
- Owner: radutopala
- License: mit
- Created: 2019-10-14T05:41:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-05T20:51:25.000Z (almost 2 years ago)
- Last Synced: 2025-02-13T23:32:32.917Z (4 months ago)
- Topics: go, golang, grpc, grpc-gateway, grpc-go, grpc-server, k8s, protobuf
- Language: Go
- Homepage:
- Size: 83 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gRPC Calculator
[](https://github.com/radutopala/grpc-calculator/actions)
A gRPC protobuf k8s calculator made in Go.
## Usage
### Server
```
go run cmd/server/main.go
```
```
NAME:
main - Calculator ServerUSAGE:
main [global options] command [command options] [arguments...]VERSION:
0.0.1COMMANDS:
help, h Shows a list of commands or help for one commandGLOBAL OPTIONS:
--bind-http value bind address for HTTP (default: ":8080") [$BIND_HTTP]
--bind-grpc value bind address for gRPC (default: ":2338") [$BIND_GRPC]
--bind-prometheus-http value bind prometheus address for HTTP (default: ":8081") [$BIND_PROMETHEUS_HTTP]
--jaeger-host value Jaeger hostname (default: "127.0.0.1") [$JAEGER_HOST]
--jaeger-port value Jaeger port (default: 5775) [$JAEGER_PORT]
--jaeger-sampler value Jaeger sampler (default: 0.05) [$JAEGER_SAMPLER]
--jaeger-tags value Jaeger tags (default: "calculator") [$JAEGER_TAGS]
--help, -h show help
--version, -v print the version
```This will provide 3 endpoints:
* gRPC at `localhost:2338`
* HTTP at `http://localhost:8080`
* Prometheus at `http://localhost:8081`## Client
Have the server run and then execute one of the following.
### HTTP
```
curl -X POST -H "Content-Type: application/json" -d '{"expression":"3+5+(10*2)"}' "http://localhost:8080/compute"
{"result": "28"}
```### gRPC
#### via `grpc_cli`
To install `grpc_cli` on a Mac, run `brew install grpc`.```
grpc_cli call localhost:2338 Compute 'expression: "3+5+(10*2)"'
connecting to localhost:2338
result: "28"Rpc succeeded with OK status
```#### via local client
```
go run cmd/client/main.go 3+5+(10*2)
```## Infra
### Docker
Server docker image is auto-published via Github Actions at [radutopala/grpc-calculator](https://hub.docker.com/r/radutopala/grpc-calculator)#### Run locally
```
docker run -p8080:8080 -p2338:2338 radutopala/grpc-calculator:v0.0.1
```### Kubernetes
#### Minikube on Mac
Should have installed: minikube, kubectl
> Run `kubectl version` and make sure you have the same major and minor versions for both client and server, else you'll get errors.
```
minikube start
kubectl apply -f infra/k8s/nginx-ingress-mandatory.yaml
minikube addons enable ingress
kubectl apply -f infra/k8s/ingress.yaml
kubectl apply -f infra/k8s/deployment.yaml
curl -kL -X POST -H "Content-Type: application/json" -d '{"expression":"3+5+(10*2)"}' http://192.168.99.100/compute
{"result":"28"}
```
where `192.168.99.100` is the external IP of Minikube.