package lazycontrolplane ¶
import "golazy.dev/lazycontrolplane"
Types ¶
type Builder ¶
Builder creates a control plane for lazyapp.
Config and *ControlPlane implement Builder. This keeps lazyapp.Config's ControlPlane field optional while still allowing ControlPlane: Config{}.
type Builder interface {
BuildControlPlane() *ControlPlane
}
type Config ¶
Config describes the operational endpoints exposed by a control plane.
The zero Config exposes /livez and /readyz.
type Config struct {
Readiness []ReadinessCheck
Metrics http.Handler
Pprof bool
}
func (config Config) BuildControlPlane ¶
BuildControlPlane implements Builder.
func (config Config) BuildControlPlane() *ControlPlane
type ControlPlane ¶
ControlPlane routes operational endpoints.
type ControlPlane struct {
// contains filtered or unexported fields
}
func New ¶
New builds a control plane from config.
func New(config Config) *ControlPlane
func (plane *ControlPlane) AddReadinessCheck ¶
AddReadinessCheck appends a readiness check to /readyz.
func (plane *ControlPlane) AddReadinessCheck(check ReadinessCheck)
func (plane *ControlPlane) BuildControlPlane ¶
BuildControlPlane implements Builder.
func (plane *ControlPlane) BuildControlPlane() *ControlPlane
func (plane *ControlPlane) EnablePprof ¶
EnablePprof registers the standard net/http/pprof handlers.
It is safe to call EnablePprof more than once.
func (plane *ControlPlane) EnablePprof()
func (plane *ControlPlane) Handle ¶
Handle registers an exact control-plane endpoint.
func (plane *ControlPlane) Handle(pattern string, handler http.Handler)
func (plane *ControlPlane) Handler ¶
Handler mounts the control plane in front of next.
func (plane *ControlPlane) Handler(next http.Handler) http.Handler
func (plane *ControlPlane) HandlesPath ¶
HandlesPath reports whether path belongs to the control plane.
func (plane *ControlPlane) HandlesPath(path string) bool
func (plane *ControlPlane) ServeHTTP ¶
ServeHTTP serves control-plane endpoints.
func (plane *ControlPlane) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (plane *ControlPlane) StandaloneHandler ¶
StandaloneHandler serves the control plane on its own listener.
It adds a root HTML index that lists registered endpoints. Use Handler when the control plane shares an application listener so "/" stays owned by the app.
func (plane *ControlPlane) StandaloneHandler() http.Handler
type ReadinessCheck ¶
ReadinessCheck is evaluated by /readyz.
type ReadinessCheck struct {
Name string
Check func(context.Context) error
}
Package lazycontrolplane provides operational HTTP endpoints for GoLazy applications.
A control plane owns framework and operations routes that should not be part of the application's route table. The zero Config is useful: it creates GET /livez and GET /readyz. /livez reports that the process can answer HTTP requests. /readyz runs configured ReadinessCheck functions and returns 503 Service Unavailable when any dependency or runtime state says the app is not ready to receive traffic.
The package can be used directly with net/http, but most applications pass a Config or *ControlPlane to lazyapp.Config.ControlPlane. lazyapp builds the control plane, adds package-owned endpoints for configured jobs and telemetry, and, when built with the lazydev tag, registers development control endpoints from packages such as lazyassets, lazybuildinfo, lazycache, lazycontroller, lazydeps, lazyjobs, lazyroutes, and lazytelemetry.
lazyapp decides where the plane is served. In production builds it does not intercept application requests unless CONTROL_PLANE_ADDR is set to the same listen address as the app. When CONTROL_PLANE_ADDR points at a different address, lazyapp serves ControlPlane.StandaloneHandler on that listener; the standalone handler adds a small root index and keeps application "/" routes separate. In lazydev builds, lazyapp keeps the control plane available on the app handler so the development panel can call it.
Custom operational endpoints can be registered with ControlPlane.Handle. Use Config.Metrics or a custom handler for /metrics, and use Config.Pprof or ControlPlane.EnablePprof to attach the standard net/http/pprof handlers.