security

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIP

func CheckIP(ip string, list []string) bool

checkIP checks if IP is in list

func IsCrawler

func IsCrawler(url string, ip string, useragent string, banDuration time.Duration) bool

IsCrawler detects crawlers/spiders/bots by user agent, ip and url

func SetBannedIP

func SetBannedIP(ip string)

SetBannedIP registers IP to banned list

Types

type Collector

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

A collector can keep track of multiple leaky buckets

func GetCollector

func GetCollector() *Collector

Return the collector

func NewCollector

func NewCollector(rate float64, capacity int64) *Collector

Creates a new collector and check for empty buckets

func (*Collector) Add

func (c *Collector) Add(key string, amount int64) int64

func (*Collector) Remove

func (c *Collector) Remove(key string)

Remove internal bucket associated with key

type LeakyBucket

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

func NewLeakyBucket

func NewLeakyBucket(rate float64, capacity int64) *LeakyBucket

NewLeakyBucket creates a new LeakyBucket with the give rate and capacity.

func (*LeakyBucket) Add

func (b *LeakyBucket) Add(amount int64) int64

Jump to

Keyboard shortcuts

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