25 lines
450 B
Go
25 lines
450 B
Go
|
package limiter
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/juju/ratelimit"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type LimiterIface interface {
|
||
|
Key(c *gin.Context) string
|
||
|
GetBucket(key string) (*ratelimit.Bucket, bool)
|
||
|
AddBuckets(rules ...LimiterBucketRule) LimiterIface
|
||
|
}
|
||
|
|
||
|
type Limiter struct {
|
||
|
limiterBuckets map[string]*ratelimit.Bucket
|
||
|
}
|
||
|
|
||
|
type LimiterBucketRule struct {
|
||
|
Key string
|
||
|
FillInterval time.Duration
|
||
|
Capacity int64
|
||
|
Quantum int64
|
||
|
}
|