Skip to content

MrWaggel/golimiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golimiter

Go Reference Go Report Card

This packages provides a key based limiter. Read more here.

Usage

go get

go get github.com/mrwaggel/golimiter

example

package main

import (
	"github.com/mrwaggel/golimiter"
	"time"
)

func main() {
	l := golimiter.New(4, time.Second*5)
	key := "a"

	l.Increment(key)
	l.Increment(key)
	l.Increment(key)

	l.Count(key)     // 3
	l.IsLimited(key) // false

	l.Increment(key)

	l.Count(key)     // 4
	l.IsLimited(key) // true

	time.Sleep(time.Second * 6)
	l.Count(key)     // 0
	l.IsLimited(key) // false
}

About

A key based limiter for go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages