Documentation
¶
Overview ¶
Package healthx 提供健康检查结果、探针接口和聚合规则。
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HealthChecker ¶
type HealthChecker interface {
Name() string
Check(ctx context.Context) HealthStatus
}
type HealthStatus ¶
type HealthStatus struct {
Name string `json:"name"`
Status HealthStatusValue `json:"status"`
Message string `json:"message"`
CheckedAt time.Time `json:"checked_at"`
LatencyMs int64 `json:"latency_ms"`
Metadata map[string]string `json:"metadata"`
}
func Aggregate ¶
func Aggregate(name string, statuses ...HealthStatus) HealthStatus
Example ¶
package main
import (
"time"
"github.com/ZoneCNH/kernel/healthx"
)
func main() {
db := healthx.NewHealthStatus("db", healthx.HealthHealthy, "ok", time.Now(), 1)
cache := healthx.NewHealthStatus("cache", healthx.HealthDegraded, "slow", time.Now(), 20)
_ = healthx.Aggregate("service", db, cache)
}
Output:
func NewHealthStatus ¶
func NewHealthStatus(name string, status HealthStatusValue, message string, checkedAt time.Time, latencyMs int64) HealthStatus
func (HealthStatus) IsHealthy ¶
func (s HealthStatus) IsHealthy() bool
func (HealthStatus) MarshalJSON ¶
func (s HealthStatus) MarshalJSON() ([]byte, error)
func (HealthStatus) WithMetadata ¶
func (s HealthStatus) WithMetadata(key string, value string) HealthStatus
type HealthStatusValue ¶
type HealthStatusValue string
const ( HealthHealthy HealthStatusValue = "healthy" HealthDegraded HealthStatusValue = "degraded" HealthUnhealthy HealthStatusValue = "unhealthy" )
type Probe ¶
type Probe interface{ HealthChecker }
Click to show internal directories.
Click to hide internal directories.