Change: rename some field

This commit is contained in:
gVisor bot 2020-03-07 20:01:24 +08:00
parent ad85f0934a
commit 3086b68798
2 changed files with 62 additions and 7 deletions

View file

@ -150,7 +150,7 @@ experimental:
# ipcidr: # ips in these subnets will be considered polluted # ipcidr: # ips in these subnets will be considered polluted
# - 240.0.0.0/4 # - 240.0.0.0/4
Proxy: proxies:
# shadowsocks # shadowsocks
# The supported ciphers(encrypt methods): # The supported ciphers(encrypt methods):
# aes-128-gcm aes-192-gcm aes-256-gcm # aes-128-gcm aes-192-gcm aes-256-gcm
@ -243,7 +243,7 @@ Proxy:
# mode: http # or tls # mode: http # or tls
# host: bing.com # host: bing.com
Proxy Group: proxy-groups:
# url-test select which proxy will be used by benchmarking speed to a URL. # url-test select which proxy will be used by benchmarking speed to a URL.
- name: "auto" - name: "auto"
type: url-test type: url-test
@ -284,7 +284,33 @@ Proxy Group:
- vmess1 - vmess1
- auto - auto
Rule: - name: UseProvider
type: select
use:
- provider1
proxies:
- Proxy
- DIRECT
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-SUFFIX,google.com,auto
- DOMAIN-KEYWORD,google,auto - DOMAIN-KEYWORD,google,auto
- DOMAIN,google.com,auto - DOMAIN,google.com,auto

View file

@ -106,13 +106,19 @@ type RawConfig struct {
ExternalUI string `yaml:"external-ui"` ExternalUI string `yaml:"external-ui"`
Secret string `yaml:"secret"` 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"` Hosts map[string]string `yaml:"hosts"`
DNS RawDNS `yaml:"dns"` DNS RawDNS `yaml:"dns"`
Experimental Experimental `yaml:"experimental"` Experimental Experimental `yaml:"experimental"`
Proxy []map[string]interface{} `yaml:"Proxy"` Proxy []map[string]interface{} `yaml:"proxies"`
ProxyGroup []map[string]interface{} `yaml:"Proxy Group"` ProxyGroup []map[string]interface{} `yaml:"proxy-groups"`
Rule []string `yaml:"Rule"` 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 // Parse config
@ -152,6 +158,11 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
"8.8.8.8", "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 { 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 groupsConfig := cfg.ProxyGroup
providersConfig := cfg.ProxyProvider 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() { defer func() {
// Destroy already created provider when err != nil // Destroy already created provider when err != nil
if err != nil { if err != nil {
@ -351,6 +374,12 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, error) {
rules := []C.Rule{} rules := []C.Rule{}
rulesConfig := cfg.Rule rulesConfig := cfg.Rule
// remove after 1.0
if len(rules) == 0 {
rulesConfig = cfg.RuleOld
}
// parse rules // parse rules
for idx, line := range rulesConfig { for idx, line := range rulesConfig {
rule := trimArr(strings.Split(line, ",")) rule := trimArr(strings.Split(line, ","))