health

package
v4.0.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: MIT Imports: 7 Imported by: 0

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 http.Handler) http.Handler

Middleware 将当前中间件应用于 next

func (*Health) MiddlewareFunc

func (h *Health) MiddlewareFunc(next func(w http.ResponseWriter, r *http.Request)) http.Handler

MiddlewareFunc 将当前中间件应用于 next

func (*Health) Register

func (h *Health) Register(method, path string)

Register 注册 api

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

func (*Health) States

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

States 返回所有的状态列表

type State

type State struct {
	Method, Path string
	Min, Max     time.Duration
	Count        int           // 总的请求次数
	UserErrors   int           // 用户端出错次数,400-499
	ServerErrors int           // 服务端出错次数,>500
	Last         time.Time     // 最后的访问时间
	Spend        time.Duration // 总花费的时间
}

State 实际存在的数据类型

type Store

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

	// Save 保存数据内容
	//
	// 每生成一条数据,均会以异步的方式调用 Save,由处理具体的操作方式。
	Save(*State)

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

Store 存储 API 状态的接口

func NewCache

func NewCache(c cache.Cache, prefix string, errlog *log.Logger) Store

NewCache 将 cache 作为存储介质

prefix 存储时,统一的前缀名称,防止重名; errlog 当存储出错时,错误信息将保存到 errlog;

Jump to

Keyboard shortcuts

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