Categorygithub.com/go-zoox/counter
modulepackage
1.2.1
Repository: https://github.com/go-zoox/counter.git
Documentation: pkg.go.dev

# README

Counter

Simple Counter, used to count requests or other events, expecially RateLimit.

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/counter

Getting Started

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)
	}
}

Inspired By

  • abo/rerate - redis-based rate counter and rate limiter
  • go-zoox/ratelimit - rate limiter, support in-memory, redis-based, other-databses

License

GoZoox is released under the MIT License.

# Packages

No description provided by the author

# Functions

New creates a counter.
NewMemory creates a in-memory counter.
NewRedis creates a redis-based counter.

# Variables

Version is the current version of the package.

# Structs

Counter count total occurs during a period.