Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LivezHandler ¶
func LivezHandler() http.HandlerFunc
func ReadyzHandler ¶
func Register ¶
Register mounts /livez and /readyz on the provided mux.
Example ¶
package main
import (
"context"
"fmt"
"log/slog"
"net/http"
"net/http/httptest"
"time"
"github.com/krateo-platformops/plumbing/server/probes"
)
type okPinger struct{}
func (okPinger) Ping(context.Context) error { return nil }
func main() {
mux := http.NewServeMux()
probes.Register(mux, slog.Default(), okPinger{}, time.Second)
req := httptest.NewRequest(http.MethodGet, "/readyz", nil)
rr := httptest.NewRecorder()
mux.ServeHTTP(rr, req)
fmt.Println(rr.Code)
}
Output: 200
Types ¶
type HealthServer ¶
type HealthServer struct {
// contains filtered or unexported fields
}
func New ¶
func New(log *slog.Logger, pinger Pinger, port int) *HealthServer
New builds an HTTP health server exposing /livez and /readyz.
The readiness probe requires that the Pinger does not return error. Liveness always returns 200.
Example ¶
package main
import (
"context"
"log/slog"
"time"
"github.com/krateo-platformops/plumbing/server/probes"
)
type okPinger struct{}
func (okPinger) Ping(context.Context) error { return nil }
func main() {
hs := probes.New(slog.Default(), okPinger{}, 0)
hs.Start()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
_ = hs.Shutdown(ctx)
}
Output:
func (*HealthServer) Shutdown ¶
func (h *HealthServer) Shutdown(ctx context.Context) error
Shutdown gracefully stops the HTTP server.
func (*HealthServer) Start ¶
func (h *HealthServer) Start()
Start runs the HTTP server in a background goroutine.
Click to show internal directories.
Click to hide internal directories.