healthserver

package module
v0.1.0 Latest Latest
Warning

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

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

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

func Register(e *echo.Echo, probes *health.Probes) error

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)
}

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures a standalone Server during construction.

func WithAddress

func WithAddress(address string) Option

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

func NewServer(probes *health.Probes, options ...Option) (*Server, error)

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) Address

func (s *Server) Address() string

Address returns the configured listen address.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the configured TCP listener and blocks until shutdown or failure.

func (*Server) Serve

func (s *Server) Serve(listener net.Listener) error

Serve accepts HTTP connections from listener and blocks until shutdown or failure.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the standalone server using ctx as its deadline.

Directories

Path Synopsis
internal
generated
Package generated contains the generated Echo 5 health server contract.
Package generated contains the generated Echo 5 health server contract.

Jump to

Keyboard shortcuts

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