Change: rename some field
This commit is contained in:
@ -106,13 +106,19 @@ type RawConfig struct {
|
||||
ExternalUI string `yaml:"external-ui"`
|
||||
Secret string `yaml:"secret"`
|
||||
|
||||
ProxyProvider map[string]map[string]interface{} `yaml:"proxy-provider"`
|
||||
ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"`
|
||||
Hosts map[string]string `yaml:"hosts"`
|
||||
DNS RawDNS `yaml:"dns"`
|
||||
Experimental Experimental `yaml:"experimental"`
|
||||
Proxy []map[string]interface{} `yaml:"Proxy"`
|
||||
ProxyGroup []map[string]interface{} `yaml:"Proxy Group"`
|
||||
Rule []string `yaml:"Rule"`
|
||||
Proxy []map[string]interface{} `yaml:"proxies"`
|
||||
ProxyGroup []map[string]interface{} `yaml:"proxy-groups"`
|
||||
Rule []string `yaml:"rules"`
|
||||
|
||||
// remove after 1.0
|
||||
ProxyProviderOld map[string]map[string]interface{} `yaml:"proxy-provider"`
|
||||
ProxyOld []map[string]interface{} `yaml:"Proxy"`
|
||||
ProxyGroupOld []map[string]interface{} `yaml:"Proxy Group"`
|
||||
RuleOld []string `yaml:"Rule"`
|
||||
}
|
||||
|
||||
// Parse config
|
||||
@ -152,6 +158,11 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
||||
"8.8.8.8",
|
||||
},
|
||||
},
|
||||
|
||||
// remove after 1.0
|
||||
RuleOld: []string{},
|
||||
ProxyOld: []map[string]interface{}{},
|
||||
ProxyGroupOld: []map[string]interface{}{},
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal(buf, &rawCfg); err != nil {
|
||||
@ -245,6 +256,18 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
||||
groupsConfig := cfg.ProxyGroup
|
||||
providersConfig := cfg.ProxyProvider
|
||||
|
||||
if len(proxiesConfig) == 0 {
|
||||
proxiesConfig = cfg.ProxyOld
|
||||
}
|
||||
|
||||
if len(groupsConfig) == 0 {
|
||||
groupsConfig = cfg.ProxyGroupOld
|
||||
}
|
||||
|
||||
if len(providersConfig) == 0 {
|
||||
providersConfig = cfg.ProxyProvider
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// Destroy already created provider when err != nil
|
||||
if err != nil {
|
||||
@ -351,6 +374,12 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, error) {
|
||||
rules := []C.Rule{}
|
||||
|
||||
rulesConfig := cfg.Rule
|
||||
|
||||
// remove after 1.0
|
||||
if len(rules) == 0 {
|
||||
rulesConfig = cfg.RuleOld
|
||||
}
|
||||
|
||||
// parse rules
|
||||
for idx, line := range rulesConfig {
|
||||
rule := trimArr(strings.Split(line, ","))
|
||||
|
Reference in New Issue
Block a user