You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
653 B
41 lines
653 B
6 years ago
|
package ratelimit
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
)
|
||
|
|
||
|
// Op operations type.
|
||
|
type Op int
|
||
|
|
||
|
const (
|
||
|
// Success opertion type: success
|
||
|
Success Op = iota
|
||
|
// Ignore opertion type: ignore
|
||
|
Ignore
|
||
|
// Drop opertion type: drop
|
||
|
Drop
|
||
|
)
|
||
|
|
||
|
type allowOptions struct{}
|
||
|
|
||
|
// AllowOptions allow options.
|
||
|
type AllowOption interface {
|
||
|
Apply(*allowOptions)
|
||
|
}
|
||
|
|
||
|
// DoneInfo done info.
|
||
|
type DoneInfo struct {
|
||
|
Err error
|
||
|
Op Op
|
||
|
}
|
||
|
|
||
|
// DefaultAllowOpts returns the default allow options.
|
||
|
func DefaultAllowOpts() allowOptions {
|
||
|
return allowOptions{}
|
||
|
}
|
||
|
|
||
|
// Limiter limit interface.
|
||
|
type Limiter interface {
|
||
|
Allow(ctx context.Context, opts ...AllowOption) (func(info DoneInfo), error)
|
||
|
}
|