diff --git a/adapter/provider/parser.go b/adapter/provider/parser.go index bd393569..d91aa4a1 100644 --- a/adapter/provider/parser.go +++ b/adapter/provider/parser.go @@ -60,5 +60,5 @@ func ParseProxyProvider(name string, mapping map[string]interface{}) (types.Prox interval := time.Duration(uint(schema.Interval)) * time.Second filter := schema.Filter - return NewProxySetProvider(name, interval, filter, vehicle, hc), nil + return NewProxySetProvider(name, interval, filter, vehicle, hc) } diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index c042b2de..6a5e3052 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -96,7 +96,11 @@ func stopProxyProvider(pd *ProxySetProvider) { pd.fetcher.Destroy() } -func NewProxySetProvider(name string, interval time.Duration, filter string, vehicle types.Vehicle, hc *HealthCheck) *ProxySetProvider { +func NewProxySetProvider(name string, interval time.Duration, filter string, vehicle types.Vehicle, hc *HealthCheck) (*ProxySetProvider, error) { + if _, err := regexp.Compile(filter); err != nil { + return nil, fmt.Errorf("invalid filter regex: %w", err) + } + if hc.auto() { go hc.process() } @@ -150,7 +154,7 @@ func NewProxySetProvider(name string, interval time.Duration, filter string, veh wrapper := &ProxySetProvider{pd} runtime.SetFinalizer(wrapper, stopProxyProvider) - return wrapper + return wrapper, nil } // for auto gc