add traffic limiter option for handler
This commit is contained in:
@ -10,7 +10,40 @@ type Limiter interface {
|
||||
Set(n int)
|
||||
}
|
||||
|
||||
type TrafficLimiter interface {
|
||||
In(key string) Limiter
|
||||
Out(key string) Limiter
|
||||
type Options struct {
|
||||
Network string
|
||||
Addr string
|
||||
Client string
|
||||
Src string
|
||||
}
|
||||
|
||||
type Option func(opts *Options)
|
||||
|
||||
func NetworkOption(network string) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Network = network
|
||||
}
|
||||
}
|
||||
|
||||
func AddrOption(addr string) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Addr = addr
|
||||
}
|
||||
}
|
||||
|
||||
func ClientOption(client string) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Client = client
|
||||
}
|
||||
}
|
||||
|
||||
func SrcOption(src string) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Src = src
|
||||
}
|
||||
}
|
||||
|
||||
type TrafficLimiter interface {
|
||||
In(ctx context.Context, key string, opts ...Option) Limiter
|
||||
Out(ctx context.Context, key string, opts ...Option) Limiter
|
||||
}
|
||||
|
Reference in New Issue
Block a user