ready

package
v1.0.442 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ready provides an http.Handler wrapper that gates requests on a readiness check. While ServiceStatus.IsReady reports false every request is answered with a JSON 503 "not_ready" error instead of reaching the delegate handler.

h := ready.NewServiceStatusVerifier(server, next)

restserver uses it so that a server whose services are still initialising (or that has stopped serving) reports unavailable to load balancers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServiceStatusVerifier

func NewServiceStatusVerifier(s ServiceStatus, delegate http.Handler) http.Handler

NewServiceStatusVerifier returns a ServiceReadyVerifier that answers requests with a JSON 503 not_ready error (via marshal.WriteJSON) carrying the request's correlation ID while s is not ready, and chains to delegate otherwise. The error is built per request; nothing is shared.

Types

type ServiceReadyVerifier

type ServiceReadyVerifier struct {
	// Status is the readiness probe.
	Status ServiceStatus
	// Delegate handles requests while Status is ready.
	Delegate http.Handler
	// NotReadyHandler handles requests while Status is not ready.
	NotReadyHandler http.Handler
}

ServiceReadyVerifier is a http.Handler that checks if the service is ready to serve, and if so chains to Delegate, otherwise calls NotReadyHandler. All fields must be set; NewServiceStatusVerifier provides the JSON 503 default for NotReadyHandler.

func (*ServiceReadyVerifier) ServeHTTP

func (c *ServiceReadyVerifier) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

type ServiceStatus

type ServiceStatus interface {
	// IsReady reports whether requests may be served right now. It is
	// called concurrently and must be cheap and safe for concurrent use.
	IsReady() bool
}

ServiceStatus is the readiness probe consulted on every request. restserver.Server satisfies it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL