diff --git a/adapter/provider/parser.go b/adapter/provider/parser.go index 1ea7b365..a91bd7c6 100644 --- a/adapter/provider/parser.go +++ b/adapter/provider/parser.go @@ -27,7 +27,7 @@ type healthCheckSchema struct { type proxyProviderSchema struct { Type string `provider:"type"` - Path string `provider:"path"` + Path string `provider:"path,omitempty"` URL string `provider:"url,omitempty"` Interval int `provider:"interval,omitempty"` Filter string `provider:"filter,omitempty"` @@ -59,14 +59,20 @@ func ParseProxyProvider(name string, mapping map[string]any) (types.ProxyProvide hcInterval = uint(schema.HealthCheck.Interval) } hc := NewHealthCheck([]C.Proxy{}, schema.HealthCheck.URL, hcInterval, schema.HealthCheck.Lazy, expectedStatus) - path := C.Path.Resolve(schema.Path) var vehicle types.Vehicle switch schema.Type { case "file": + path := C.Path.Resolve(schema.Path) vehicle = resource.NewFileVehicle(path) case "http": - vehicle = resource.NewHTTPVehicle(schema.URL, path) + if schema.Path != "" { + path := C.Path.Resolve(schema.Path) + vehicle = resource.NewHTTPVehicle(schema.URL, path) + } else { + path := C.Path.GetPathByHash("proxies", schema.URL) + vehicle = resource.NewHTTPVehicle(schema.URL, path) + } default: return nil, fmt.Errorf("%w: %s", errVehicleType, schema.Type) } diff --git a/rules/provider/parse.go b/rules/provider/parse.go index 548dacf9..81b9cb49 100644 --- a/rules/provider/parse.go +++ b/rules/provider/parse.go @@ -18,7 +18,7 @@ var ( type ruleProviderSchema struct { Type string `provider:"type"` Behavior string `provider:"behavior"` - Path string `provider:"path"` + Path string `provider:"path,omitempty"` URL string `provider:"url,omitempty"` Format string `provider:"format,omitempty"` Interval int `provider:"interval,omitempty"` @@ -54,13 +54,19 @@ func ParseRuleProvider(name string, mapping map[string]interface{}, parse func(t return nil, fmt.Errorf("unsupported format type: %s", schema.Format) } - path := C.Path.Resolve(schema.Path) var vehicle P.Vehicle switch schema.Type { case "file": + path := C.Path.Resolve(schema.Path) vehicle = resource.NewFileVehicle(path) case "http": - vehicle = resource.NewHTTPVehicle(schema.URL, path) + if schema.Path != "" { + path := C.Path.Resolve(schema.Path) + vehicle = resource.NewHTTPVehicle(schema.URL, path) + } else { + path := C.Path.GetPathByHash("rules", schema.URL) + vehicle = resource.NewHTTPVehicle(schema.URL, path) + } default: return nil, fmt.Errorf("unsupported vehicle type: %s", schema.Type) }