add traffic limiter option for handler

This commit is contained in:
ginuerzh
2023-11-18 18:25:40 +08:00
parent a916f04016
commit 486f2cee61
2 changed files with 44 additions and 3 deletions

View File

@ -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
}