healthx

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 3 Imported by: 0

README

healthx 包 Package

healthx 定义健康状态值、健康检查接口、probe 组合和健康聚合。

Use Aggregate to collapse component health into one service-level status.

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

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 }

Jump to

Keyboard shortcuts

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