modulepackage
0.1.0
Repository: https://github.com/tomweston/tm-calculator.git
Documentation: pkg.go.dev
# README
tm-calculator

A Golang Calculator API built with Gorilla Mux Router and Prometheus Metrics ready to deploy to Kubernetes.
Deploying the tm-calculator API to Kubernetes
To deploy it, run the following command:
kubectl apply -f https://raw.githubusercontent.com/tomweston/tm-calculator/master/kubernetes/manifest.yml
Accessing the tm-calculator API
kubectl --namespace=tm-calculator port-forward svc/tm-calculator-service 5555:5555
Examples
- GET - 10 random numbers (if no num provided):
curl http://localhost:5555/api/v1/random
- GET - 100 random numbers:
curl http://localhost:5555/api/v1/random?num=100
- GET - Add 20 to 10:
curl http://localhost:9000/api/v1/add?num1=20&num2=10
- GET - Subtract 5 from 10:
curl http://localhost:5555/api/v1/subtract?num1=10&num2=5
- GET - Divide 10 by 2:
curl http://localhost:5555/api/v1/division?num1=10&num2=2
Health
- GET - Readiness:
curl http://localhost:5555/readiness
- GET - Liveness:
curl http://localhost:5555/liveness
Collections
Testing
go test -v ./...
Build & Run with Docker
docker build -t tm-calculator .
docker run -d -p 5555:5555 tm-calculator
Local Install
go build
./tm-calculator
Prometheus Metrics
Metrics curl http://localhost:5555/metrics
Included Metrics
processed_adds_total
- The total number of processed add events
processed_subtracts_total
- The total number of processed subtraction events
processed_division_total
- The total number of processed division events
processed_random_total
- The total number of processed random events
Kubernetes
Deploy
kubectl apply -f manifest.yml
Port Forward
kubectl --namespace=tm-calculator port-forward svc/tm-calculator-service 5555:5555
# Packages
No description provided by the author
# Functions
Alive returns true if the server is alive.
IndexHandler handles the root route.
LivenessHandler handles the liveness route.
ReadinessHandler handles the readiness route.
Ready returns true if the server is ready.