health

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 3 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) 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 {
	// 获取指定 API 的数据
	//
	// 如果还不存在,则返回空对象。
	Get(method, path string) *State

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

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

Store 存储 API 状态的处理接口

func NewMemory

func NewMemory(capacity int64) Store

NewMemory 声明 Store 的内存实现方式

Jump to

Keyboard shortcuts

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