add context for modules

This commit is contained in:
ginuerzh
2023-04-18 20:46:44 +08:00
parent f3482d7cd8
commit a2115a3d38
8 changed files with 24 additions and 15 deletions

View File

@ -1,9 +1,11 @@
package bypass
import "context"
// Bypass is a filter of address (IP or domain).
type Bypass interface {
// Contains reports whether the bypass includes addr.
Contains(addr string) bool
Contains(ctx context.Context, addr string) bool
}
type bypassGroup struct {
@ -16,9 +18,9 @@ func BypassGroup(bypasses ...Bypass) Bypass {
}
}
func (p *bypassGroup) Contains(addr string) bool {
func (p *bypassGroup) Contains(ctx context.Context, addr string) bool {
for _, bypass := range p.bypasses {
if bypass != nil && bypass.Contains(addr) {
if bypass != nil && bypass.Contains(ctx, addr) {
return true
}
}