add network for bypass

This commit is contained in:
ginuerzh
2023-09-30 17:48:40 +08:00
parent b0bd45c1b8
commit bf3b76a273
4 changed files with 41 additions and 9 deletions

View File

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