add request rate limiter

This commit is contained in:
ginuerzh
2022-09-14 19:53:21 +08:00
parent 45b7ac2021
commit 50d443049f
3 changed files with 26 additions and 6 deletions

View File

@ -7,17 +7,19 @@ import (
"github.com/go-gost/core/auth"
"github.com/go-gost/core/bypass"
"github.com/go-gost/core/chain"
"github.com/go-gost/core/limiter/rate"
"github.com/go-gost/core/logger"
"github.com/go-gost/core/metadata"
)
type Options struct {
Bypass bypass.Bypass
Router *chain.Router
Auth *url.Userinfo
Auther auth.Authenticator
TLSConfig *tls.Config
Logger logger.Logger
Bypass bypass.Bypass
Router *chain.Router
Auth *url.Userinfo
Auther auth.Authenticator
RateLimiter rate.RateLimiter
TLSConfig *tls.Config
Logger logger.Logger
}
type Option func(opts *Options)
@ -46,6 +48,12 @@ func AutherOption(auther auth.Authenticator) Option {
}
}
func RateLimiterOption(limiter rate.RateLimiter) Option {
return func(opts *Options) {
opts.RateLimiter = limiter
}
}
func TLSConfigOption(tlsConfig *tls.Config) Option {
return func(opts *Options) {
opts.TLSConfig = tlsConfig