add network for bypass
This commit is contained in:
@ -2,10 +2,22 @@ package bypass
|
||||
|
||||
import "context"
|
||||
|
||||
type Options struct {
|
||||
Host string
|
||||
}
|
||||
|
||||
type Option func(opts *Options)
|
||||
|
||||
func WithHostOpton(host string) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Host = host
|
||||
}
|
||||
}
|
||||
|
||||
// Bypass is a filter of address (IP or domain).
|
||||
type Bypass interface {
|
||||
// Contains reports whether the bypass includes addr.
|
||||
Contains(ctx context.Context, addr string) bool
|
||||
Contains(ctx context.Context, network, addr string, opts ...Option) bool
|
||||
}
|
||||
|
||||
type bypassGroup struct {
|
||||
@ -18,9 +30,9 @@ func BypassGroup(bypasses ...Bypass) Bypass {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *bypassGroup) Contains(ctx context.Context, addr string) bool {
|
||||
func (p *bypassGroup) Contains(ctx context.Context, network, addr string, opts ...Option) bool {
|
||||
for _, bypass := range p.bypasses {
|
||||
if bypass != nil && bypass.Contains(ctx, addr) {
|
||||
if bypass != nil && bypass.Contains(ctx, network, addr, opts...) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user