ipratelimit

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPreBlack

func AddPreBlack(ipReq string)

将ip加入小黑屋监控,超过一定评率有可能被加入小黑屋

func AllowByConn

func AllowByConn(conn net.Conn) (*waitblack.WaitT, bool)

单第二个参数为false,代表ip被限制,不允许进行后续操作; 第二个参数为true,可以进行后续业务操作,且必须在规定时间内调用第一个返回值对象的WaitT.Stop()方法,否则将会被纳入黑名单监控

func AllowByIPSimple added in v1.3.3

func AllowByIPSimple(ipReq string) bool

简单版本,只有ip限流,没用白名单,没有黑名单,返回值为true代表可以进行业务操作,false代表ip被限流

func AllowByIPStr

func AllowByIPStr(ipReq string) bool

返回值为true代表可以惊喜业务操作,false代表ip被

func Init

func Init(cfg *ConfigT)

Types

type ConfigT

type ConfigT struct {
	WhiteIPStrSli        []string      // ip白名单
	RateSpeed            int           // 默认令牌桶产生令牌的速率
	BucketLen            int           // 令牌桶大小
	OnBlackDuration      time.Duration // 触发小黑屋,关多久
	WaitConnReadDuration time.Duration // 套接字等待多久判断空连接
	BlackTimes           int           // 结合intervalSecond参数,代表在intervalSecond的时间间隔内(s),产生多少次将触发小黑屋
	IntervalSecond       int           // 结合blackTimes

}

Directories

Path Synopsis
internal
typ

Jump to

Keyboard shortcuts

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