throttle

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package throttle 限流

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrHandler

func DefaultErrHandler(ctx zeroapi.Context, err error)

DefaultErrHandler 默认的发生错误时调用

func DefaultLimitHandler

func DefaultLimitHandler(ctx zeroapi.Context)

DefaultLimitHandler 默认的发生限制时调用

func New

func New(c *Config) zeroapi.Handler

Types

type Config

type Config struct {
	// LimitHandler 发生限制时调用
	LimitHandler zeroapi.Handler

	// ErrHandler 发生错误时调用
	ErrHandler func(ctx zeroapi.Context, err error)

	// PerMin 每个请求每分钟请求的个数,> 0
	PerMin int

	// Burst 每一个请求每分钟允许额外请求的个数,> 0
	Burst int

	// VaryBy 为请求生成唯一值
	VaryBy VaryBy
}

Config 配置

type VaryBy

type VaryBy interface {
	Key(*http.Request) string
}

VaryBy 为请求生成唯一值

func DefaultVaryBy

func DefaultVaryBy() VaryBy

DefaultVaryBy 默认的 key 生成器

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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