diff --git a/README.md b/README.md index 3be09c9d..2f7aba25 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ experimental: # ipcidr: # ips in these subnets will be considered polluted # - 240.0.0.0/4 -Proxy: +proxies: # shadowsocks # The supported ciphers(encrypt methods): # aes-128-gcm aes-192-gcm aes-256-gcm @@ -243,7 +243,7 @@ Proxy: # mode: http # or tls # host: bing.com -Proxy Group: +proxy-groups: # url-test select which proxy will be used by benchmarking speed to a URL. - name: "auto" type: url-test @@ -283,8 +283,34 @@ Proxy Group: - ss2 - vmess1 - auto + + - name: UseProvider + type: select + use: + - provider1 + proxies: + - Proxy + - DIRECT -Rule: +proxy-providers: + provider1: + type: http + url: "url" + interval: 3600 + path: ./hk.yaml + health-check: + enable: true + interval: 600 + url: http://www.gstatic.com/generate_204 + test: + type: file + path: /test.yaml + health-check: + enable: true + interval: 36000 + url: http://www.gstatic.com/generate_204 + +rules: - DOMAIN-SUFFIX,google.com,auto - DOMAIN-KEYWORD,google,auto - DOMAIN,google.com,auto diff --git a/config/config.go b/config/config.go index d0260b86..0a74d9bc 100644 --- a/config/config.go +++ b/config/config.go @@ -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, ","))