Skip to content

gjbae1212/go-limiter

Repository files navigation

go-limiter

license

Go-Limiter is a rate limiter which can throttle up and back requests in a specified situation.
Go-Limiter* can apply to a custom function that revaluates a current limit of the requests in a specified situation but doesn't get out between min and max limit that you set.
Revaluate time happens periodically; of course, it supports a custom interval that you set.
It's based on memory or redis. If you use it in distributed applications, recommend redis.

Getting Started

package main
import (
    "time"
	"github.com/gjbae1212/go-limiter"
)

func main() {
    cache, _ := limiter.NewMemoryCache() // or limiter.NewRedisCache 
    
    rateLimiter, _ := limiter.NewRateLimiter("service-name", cache,
        limiter.WithEstimatePeriod(10 * time.Minute),
        limiter.WithMinLimit(10),
        limiter.WithMaxLimit(10000),
    )
   
    // ok is true : doesn't exceed limit.
    // ok is false : exceed limit. 
    ok, _ := rateLimiter.Acquire()    
}

LICENSE

This project is following The MIT.

About

Go-Limiter is a rate limiter which can throttle up and back requests in a specified situation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published