Revert "[fix]code"

This reverts commit 0431969a73.
This commit is contained in:
maze.y2b@gmail.com
2021-12-02 20:08:34 +08:00
parent b15a7c8b6f
commit 53eb3f15bb
13 changed files with 9 additions and 784 deletions

View File

@ -60,44 +60,3 @@ func ParseProxyProvider(name string, mapping map[string]interface{}) (types.Prox
interval := time.Duration(uint(schema.Interval)) * time.Second
return NewProxySetProvider(name, interval, vehicle, hc), nil
}
type ruleProviderSchema struct {
Type string `provider:"type"`
Behavior string `provider:"behavior"`
Path string `provider:"path"`
URL string `provider:"url,omitempty"`
Interval int `provider:"interval,omitempty"`
}
func ParseRuleProvider(name string, mapping map[string]interface{}) (types.RuleProvider, error) {
schema := &ruleProviderSchema{}
decoder := structure.NewDecoder(structure.Option{TagName: "provider", WeaklyTypedInput: true})
if err := decoder.Decode(mapping, schema); err != nil {
return nil, err
}
var behavior Behavior
switch schema.Behavior {
case "domain":
behavior = Domain
case "ipcidr":
behavior = IPCIDR
case "classical":
behavior = Classical
default:
return nil, fmt.Errorf("unsupported behavior type: %s", schema.Behavior)
}
path := C.Path.Resolve(schema.Path)
var vehicle types.Vehicle
switch schema.Type {
case "file":
vehicle = NewFileVehicle(path)
case "http":
vehicle = NewHTTPVehicle(schema.URL, path)
default:
return nil, fmt.Errorf("unsupported vehicle type: %s", schema.Type)
}
interval := time.Duration(uint(schema.Interval)) * time.Second
return NewRuleSetProvider(name, behavior, interval, vehicle), nil
}