Tiny Go HTTP server that simply echoes the request it receives. May be useful for debugging clients, load‑balancers, or service meshes.
- Writing Web Applications in the Go documentation
- An Introduction to Handlers and Servemuxes in Go by Alex Edwards
- Enforce a minimum test coverage
- More logging in ./cmd/echo-service/main.go
- Integration tests (run server and test the endpoints)
- End-to-end Kubernetes tests
- Prometheus counters and a
/metricsendpoint - Container signing and hardening
Requirements vary depending on how you want to use this.
- jq for pretty-printing JSON output (optional)
- Go 1.22+ (only for
go run/ local builds) - Docker 20+ (only for the container demo)
- kubectl and a cluster (for the Kubernetes section)
- Optionally, minikube (for the Kubernetes section)
go run ./cmd/echo-service
# In another terminal:
curl -s http://localhost:8080/hello | jq .From the repository root, run:
docker build -t echo-service:0.1.0 .
docker run --rm -p 8080:8080 echo-service:0.1.0Then in another terminal instance, run:
curl -s http://localhost:8080/hello | jq .and you should get
{
"method": "GET",
"path": "/hello",
"headers": {
"Accept": [
"*/*"
],
"User-Agent": [
"curl/8.12.1"
]
},
"host": "localhost:8080",
"remote_addr": "[::1]:65325"
}For a dev environment only, start by building and loading the image locally.
# Point Docker to Minikube’s daemon
eval "$(minikube -p minikube docker-env)"
# Build the :dev tag referenced by the dev overlay
docker build -t ghcr.io/gmarmstrong/echo-service:dev .Now, regardless of environment, do the rollout:
kubectl rollout status deployment/echo-serviceWe can now verify that the rollout was successful:
kubectl port-forward svc/echo-service 8080:80 &
curl -s http://localhost:8080/hello | jq .| Path | Method | Purpose | Typical response |
|---|---|---|---|
/{any} |
GET | Echo request back as JSON | 200 application/json |
/healthz |
GET | Liveness/readiness probe | 204 No Content |
The service listens on PORT (default 8080).
You can override it by setting that environment variable using kubectl or
by editing k8s/deployment.yaml:
env:
- name: PORT
value: "9090"
ports:
- containerPort: 9090
readinessProbe:
httpGet:
path: /healthz
port: 9090
livenessProbe:
httpGet:
path: /healthz
port: 9090The Build container image workflow (.github/workflows/build-image.yml) runs on every push to main (and on tag pushes). It:
- Builds a multi‑arch Docker image with Buildx
- Tags it based on the Git ref (
v0.x.y,sha‑<digest>) - Pushes the image to GHCR
# Static analysis
go vet ./...
# Unit tests
go test ./... -v
# Check that the image builds and runs
docker build -t echo-service:dev .
docker run --rm -p 8080:8080 echo-service:devThis project uses the MIT license. See LICENSE for the full text.