Documentation
¶
Overview ¶
Package restrictor is a generated protocol buffer package.
It is generated from these files:
limiter.proto
It has these top-level messages:
Limiter
Index ¶
- Variables
- type Limiter
- func (*Limiter) Descriptor() ([]byte, []int)
- func (this *Limiter) Equal(that interface{}) bool
- func (m *Limiter) GetBuckets() map[uint32]uint32
- func (lmt *Limiter) GetCount(window uint32, now time.Time) (total uint32)
- func (m *Limiter) GetFullUntil() uint32
- func (this *Limiter) GoString() string
- func (lmt *Limiter) LimitReached(window, upperLimit, interval uint32, now time.Time) (reached bool, count uint32, lmtChanged bool, expireChanged bool)
- func (m *Limiter) Marshal() (dAtA []byte, err error)
- func (m *Limiter) MarshalTo(dAtA []byte) (int, error)
- func (*Limiter) ProtoMessage()
- func (m *Limiter) Reset()
- func (m *Limiter) Size() (n int)
- func (this *Limiter) String() string
- func (m *Limiter) Unmarshal(dAtA []byte) error
- type Restrictor
- func (r *Restrictor) GetCount(key string, window time.Duration) (count uint32, err error)
- func (r *Restrictor) LimitReached(key string) (bool, error)
- func (r *Restrictor) LimitReachedAtTime(now time.Time, key string) (bool, error)
- func (r *Restrictor) LimitReachedAtTimeWithCount(now time.Time, key string) (bool, uint32, error)
- func (r *Restrictor) LimitReachedWithCount(key string) (bool, uint32, error)
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidLengthLimiter = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowLimiter = fmt.Errorf("proto: integer overflow") )
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct { FullUntil uint32 `protobuf:"varint,2,opt,name=fullUntil,proto3" json:"fullUntil,omitempty"` Buckets map[uint32]uint32 `` /* 150-byte string literal not displayed */ }
func (*Limiter) Descriptor ¶
func (*Limiter) GetBuckets ¶
func (*Limiter) GetCount ¶
GetCount returns count of objects in bucket within defined time window. Does not modify data (read only).
func (*Limiter) GetFullUntil ¶
func (*Limiter) LimitReached ¶
func (lmt *Limiter) LimitReached(window, upperLimit, interval uint32, now time.Time) (reached bool, count uint32, lmtChanged bool, expireChanged bool)
LimitReached checks whether limits reached side effect: the limiter itself is modified if limit is not reached yet
func (*Limiter) ProtoMessage ¶
func (*Limiter) ProtoMessage()
type Restrictor ¶
type Restrictor struct {
// contains filtered or unexported fields
}
Restrictor holds general information of limits
func NewRestrictor ¶
func NewRestrictor(window time.Duration, limit, numberOfBuckets uint32, store Store) Restrictor
NewRestrictor creates a restrictor window should not be too large, it will be converted to 'seconds' limit is the max number of requests allowed in a window numberOfBuckets is number of buckets in the sliding window, usually around 100
func (*Restrictor) GetCount ¶
GetCount returns number of records 'now' within defined time window. Does not modify data (read only).
func (*Restrictor) LimitReached ¶
func (r *Restrictor) LimitReached(key string) (bool, error)
LimitReached check whether limit has been reached now
func (*Restrictor) LimitReachedAtTime ¶
LimitReachedAtTime check whether limit has been reached at time 'now'
func (*Restrictor) LimitReachedAtTimeWithCount ¶
LimitReachedAtTimeWithCount check whether limit has been reached at time 'now'
func (*Restrictor) LimitReachedWithCount ¶
func (r *Restrictor) LimitReachedWithCount(key string) (bool, uint32, error)
LimitReachedWithCount check whether limit has been reached now and returns current count for key within time window.
type Store ¶
type Store interface { GetLimiter(key string) (*Limiter, time.Time, bool) // expireAfter is in seconds SetLimiter(key string, value *Limiter, expireAfter int) error TryLock(key, mark string) (bool, error) Unlock(key, mark string) error }
Store is the interface for central storage
func NewMemoryStore ¶
NewMemoryStore creates an in-memory store
func NewRedisStore ¶
func NewRedisStore(rawurl string, options ...redis.DialOption) (Store, error)
NewRedisStore creates an store using redis