Back to godoc.org
github.com/2637309949/bulrush-limit

Package limit

v0.0.0-...-2cb72c1
Latest Go to latest

The latest major version is .

Published: Sep 23, 2019 | License: MIT | Module: github.com/2637309949/bulrush-limit

Index

type ErrorHandler

type ErrorHandler func(ctx *gin.Context)

ErrorHandler handler error

var DefaultFailureHandler ErrorHandler = func(ctx *gin.Context) {
	rushLogger.Error("rate limited access, pease check again later")
	ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"message": "rate limited access, pease check again later"})
}

DefaultFailureHandler default error handler

type Frequency

type Frequency struct {
	Passages       []string
	Rules          []Rule
	Model          Model
	FailureHandler ErrorHandler
}

Frequency limit

type Limit

type Limit struct {
	Frequency *Frequency
}

Limit plugin

func New

func New() *Limit

New defined new limit

func (*Limit) AddOptions

func (l *Limit) AddOptions(opts ...Option) *Limit

AddOptions defined add option

func (*Limit) Plugin

func (l *Limit) Plugin(router *gin.RouterGroup)

Plugin for Limit

type Model

type Model interface {
	Save(string, string, string, int)
	Find(string, string, string, int) interface{}
}

Model token store

type Option

type Option func(*Limit) interface{}

Option defined implement of option

type RedisModel

type RedisModel struct {
	Model
	Redis *redisext.Redis
}

RedisModel adapter for redis

func (*RedisModel) Find

func (model *RedisModel) Find(ip string, url string, method string, rate int) interface{}

Find find a token

func (*RedisModel) Save

func (model *RedisModel) Save(ip string, url string, method string, rate int)

Save save a token

type Rule

type Rule struct {
	Methods []string
	Match   string
	Rate    int
}

Rule defined

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier