Files
homelab-frontend/internal/server/router.go
T
Story Crater BotandClaude Opus 5 058f11cf2b
CI / Test (push) Canceled after 0s
CI / Vet (push) Canceled after 0s
CI / Build (push) Canceled after 0s
CI / Security (govulncheck) (push) Canceled after 0s
chore: initial commit of Go API gateway
Baseline for the Kong replacement on api.riotpiao.com. Brings the working
tree under version control for the first time: gateway source, the task
board that drives the agent runs, test fixtures, and K8s manifests.

Anchor the gateway ignore rule to the repo root. Unanchored, "gateway"
also matched the cmd/gateway/ source directory, so the program entrypoint
was excluded from every commit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-08-19 20:54:34 -07:00

37 lines
1019 B
Go

package server
import (
"net/http"
)
// Router implements an HTTP handler that routes health endpoints
// and passes other requests to an upstream handler.
type Router struct {
healthChecker *HealthChecker
upstreamHandler http.Handler
}
// NewRouter creates a new router with health endpoints.
// Health endpoints (/healthz and /readyz) are handled locally.
// All other paths are passed to the upstream handler.
func NewRouter(healthChecker *HealthChecker, upstreamHandler http.Handler) *Router {
return &Router{
healthChecker: healthChecker,
upstreamHandler: upstreamHandler,
}
}
// ServeHTTP implements http.Handler.
// It routes /healthz and /readyz to health handlers,
// and passes all other paths to the upstream handler.
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/healthz":
LivenessHandler(r.healthChecker)(w, req)
case "/readyz":
ReadinessHandler(r.healthChecker)(w, req)
default:
r.upstreamHandler.ServeHTTP(w, req)
}
}