Simple Counter, used to count requests or other events, expecially RateLimit.
To install the package, run:
go get github.com/go-zoox/counter
import (
"testing"
"github.com/go-zoox/counter"
)
func main() {
id := "127.0.0.1"
r := counter.New(bucket.NewMemory(), "web", 5*time.Second)
if err := r.Inc(id); err != nil {
log.Fatal(err)
}
if v, err := r.Count(id); err != nil {
log.Fatal(err)
} else {
fmt.Println("count:", v)
}
}
- abo/rerate - redis-based rate counter and rate limiter
- go-zoox/ratelimit - rate limiter, support in-memory, redis-based, other-databses
GoZoox is released under the MIT License.