package http import ( "fmt" "net/http" dsHTTP "edge-infra.dev/pkg/edge/datasync/http" "edge-infra.dev/pkg/edge/datasync/internal/config" ) var isGRPCServerReady = false func NewReadinessServer(shouldRun chan bool, cfg *config.Config) *dsHTTP.Server { serverMux := http.NewServeMux() serverMux.HandleFunc("/readiness", readiness) return dsHTTP.NewServer(cfg.ReadinessPort, serverMux, shouldRun) } func readiness(w http.ResponseWriter, _ *http.Request) { if isServerReady() { fmt.Fprintf(w, "up") return } w.WriteHeader(http.StatusServiceUnavailable) fmt.Fprintf(w, "not ready") } // isServerReady returns a boolean indicating the server is ready to accept requests. Chirp serves // an http server and a gRPC server. Since the readiness endpoint is served through the http server // and there are no downstream dependencies to check, we can imply the http server is up. We do not // need to explicitly check for http server readiness here. func isServerReady() bool { return isGRPCServerReady } func SetIsGRPCServerReady(isReady bool) { isGRPCServerReady = isReady }