chore: add optional provider path

This commit is contained in:
xishang0128
2023-10-22 22:52:33 +08:00
committed by wwqgtxx
parent 7d58238e06
commit 347e606853
2 changed files with 18 additions and 6 deletions

View File

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