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