health

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package health 提供 liveness/readiness 探针注册表。

语义(K8s 约定):/healthz 只反映进程存活,关停期间仍返回 200,防止被提前杀死; /readyz 在全部启动钩子完成前、以及收到关停信号后返回 503,用于摘流量。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckFunc

type CheckFunc func(ctx context.Context) error

CheckFunc 把函数适配为 Checker。

func (CheckFunc) Check

func (f CheckFunc) Check(ctx context.Context) error

type Checker

type Checker interface {
	Check(ctx context.Context) error
}

Checker 是一个就绪检查。返回 error 表示未就绪。

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry 聚合各模块的就绪检查,并持有全局 ready 状态。并发安全。

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Add

func (r *Registry) Add(name string, c Checker)

Add 注册一个命名检查。同名覆盖。

func (*Registry) LiveHandler

func (r *Registry) LiveHandler() http.Handler

LiveHandler 返回 /healthz 处理器:进程活着即 200。

func (*Registry) Ready

func (r *Registry) Ready(ctx context.Context) map[string]error

Ready 执行全部检查。返回 nil 表示可以接流量。

func (*Registry) ReadyHandler

func (r *Registry) ReadyHandler() http.Handler

ReadyHandler 返回 /readyz 处理器:未就绪或任一检查失败即 503,body 只列 失败项名与固定文案 "unhealthy"——探针任何人都能打,原始错误可能携带内部 信息(连接串、拓扑),详情只经 SetLogger 注入的 logger 记录。

func (*Registry) SetLogger

func (r *Registry) SetLogger(log *slog.Logger)

SetLogger 设置检查失败详情的落点。未设置时用 slog.Default()。

func (*Registry) SetReady

func (r *Registry) SetReady(ready bool)

SetReady 设置全局就绪状态。框架在全部 OnStart 完成后置 true, 收到关停信号后立即置 false。

Jump to

Keyboard shortcuts

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