health

package
v6.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package health API 状态检测

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Health

type Health struct {
	Enabled bool // 是否启用当前的中间件
	// contains filtered or unexported fields
}

Health API 状态检测

func New

func New(store Store) *Health

New 声明 Health 实例

func (*Health) Middleware

func (h *Health) Middleware(next web.HandlerFunc) web.HandlerFunc

Middleware 将当前中间件应用于 next

func (*Health) Register

func (h *Health) Register(route, method, pattern string)

Register 注册 api

这不是一个必须的操作,默认情况下,当 api 被第一次访问时, 才会将该 api 的信息进行保存,此操作相当于提前进行一次访问。 此操作对部分冷门的 api 可以保证其出现在 States() 中。

func (*Health) States

func (h *Health) States() []*State

States 返回所有的状态列表

type State

type State struct {
	XMLName      struct{}      `xml:"state" yaml:"-" json:"-"`
	Route        string        `xml:"route" yaml:"route" json:"route"`         // 多个路由时,表示的路由名称
	Method       string        `xml:"method,attr" yaml:"method" json:"method"` // 请求方法
	Pattern      string        `xml:"pattern" yaml:"pattern" json:"pattern"`   // 路由
	Min          time.Duration `xml:"min,attr" yaml:"min" json:"min"`
	Max          time.Duration `xml:"max,attr" yaml:"max" json:"max"`
	Count        int           `xml:"count,attr" yaml:"count" json:"count"`                      // 总的请求次数
	UserErrors   int           `xml:"userErrors,attr" yaml:"userErrors" json:"userErrors"`       // 用户端出错次数,400-499
	ServerErrors int           `xml:"serverErrors,attr" yaml:"serverErrors" json:"serverErrors"` // 服务端出错次数,>500
	Last         time.Time     `xml:"last" yaml:"last" json:"last"`                              // 最后的访问时间
	Spend        time.Duration `xml:"spend,attr" yaml:"spend" json:"spend"`                      // 总花费的时间
}

State 实际存在的数据类型

type Store

type Store interface {
	// Get 获取指定 API 的数据
	//
	// 如果还不存在,则返回空对象。
	Get(route, method, pattern string) *State

	// Save 保存数据内容
	Save(*State)

	// All 返回所有接口的状态信息
	All() []*State
}

Store 存储 API 状态的接口

func NewCacheStore

func NewCacheStore(srv web.Server, prefix string) Store

NewCacheStore 基于缓存的存取接口实现

NOTE: 缓存是易失性的,不能永久性保存数据。

Jump to

Keyboard shortcuts

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