kit

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateState

type RateState struct {
	// contains filtered or unexported fields
}

RateState 通过计数增长和时间间隔计算速率

func NewRateState

func NewRateState(seconds ...float64) *RateState

NewRateState 创建速率计算器, 可选设置最小保护时间间隔, 默认 1 秒

func (*RateState) Rate

func (r *RateState) Rate(count uint64) float64

Rate 计算并返回速率(每秒), 返回最近两次触达计算的请求时间间隔之间的计数增长平均速率 非实时计算, 可能返回上一轮速率结果 非精确计算, 当计数增长突发性很大或请求的时间间隔很长时, 速率结果与实际误差较大 若需要得到相对精准的结果, 按指定时间间隔调用 Rate 函数 -1 表示计数器被重置或无效, 0 表示无变化

func (*RateState) SetMinSecond added in v0.10.2

func (r *RateState) SetMinSecond(second float64)

SetMinSecond 设置最小时间间隔 (秒)

Jump to

Keyboard shortcuts

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