Documentation
¶
Overview ¶
Package healthserver exposes health probes through an OpenAPI-generated Echo 5 transport.
Register mounts /livez and /readyz on an existing Echo instance. Existing global middleware still applies, so callers must ensure authentication does not block Kubernetes probes. NewServer creates a standalone server on :8081 with bounded HTTP timeouts. It does not install signal handlers or start goroutines; the application owns Serve or ListenAndServe and calls Shutdown explicitly.
Probe clients should use HTTP status codes. Responses contain only {"status":"ok|fail"}; /readyz?verbose=true additionally returns safe component names, statuses, and criticality. Internal checker errors are never serialized. Before the management listener is available, a refused connection from /livez is the startup failure signal.
A Kubernetes container can target the standalone server as follows:
startupProbe:
httpGet: {path: /livez, port: 8081}
timeoutSeconds: 2
livenessProbe:
httpGet: {path: /livez, port: 8081}
timeoutSeconds: 2
readinessProbe:
httpGet: {path: /readyz, port: 8081}
timeoutSeconds: 2
Keep the management port out of public Services and Ingresses. Tune startup failure thresholds to the management listener's initialization budget.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
Register adds the fixed health probe routes to e.
Example ¶
package main
import (
"github.com/devctllabs/go-libs/health"
"github.com/devctllabs/go-libs/healthserver"
"github.com/labstack/echo/v5"
)
func main() {
probes, _ := health.New()
e := echo.New()
_ = healthserver.Register(e, probes)
}
Output:
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures a standalone Server during construction.
func WithAddress ¶
WithAddress replaces the default standalone address :8081.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server owns the standalone health HTTP server lifecycle.
func NewServer ¶
NewServer creates a standalone Echo health server without starting it.
Example ¶
package main
import (
"log"
"os"
"github.com/devctllabs/go-libs/health"
"github.com/devctllabs/go-libs/healthserver"
)
func main() {
logger := log.New(os.Stdout, "", 0)
probes, _ := health.New()
server, _ := healthserver.NewServer(probes)
logger.Println(server.Address())
}
Output: :8081
func (*Server) ListenAndServe ¶
ListenAndServe starts the configured TCP listener and blocks until shutdown or failure.