chore: support KeyReplacer in Structure Decoder

This commit is contained in:
wwqgtxx
2022-11-27 13:44:38 +08:00
parent c8d7243b5b
commit a58234f0cd
3 changed files with 27 additions and 8 deletions

View File

@ -99,7 +99,6 @@ type HysteriaOption struct {
Down string `proxy:"down"`
DownSpeed int `proxy:"down-speed,omitempty"` // compatible with Stash
Auth string `proxy:"auth,omitempty"`
OldAuthString string `proxy:"auth_str,omitempty"`
AuthString string `proxy:"auth-str,omitempty"`
Obfs string `proxy:"obfs,omitempty"`
SNI string `proxy:"sni,omitempty"`

View File

@ -9,14 +9,10 @@ import (
C "github.com/Dreamacro/clash/constant"
)
func ParseProxy(mapping map[string]any) (C.Proxy, error) {
newMapping := make(map[string]any)
for key := range mapping {
newMapping[strings.ReplaceAll(key, "_", "-")] = mapping[key]
}
mapping = newMapping
var keyReplacer = strings.NewReplacer("_", "-")
decoder := structure.NewDecoder(structure.Option{TagName: "proxy", WeaklyTypedInput: true})
func ParseProxy(mapping map[string]any) (C.Proxy, error) {
decoder := structure.NewDecoder(structure.Option{TagName: "proxy", WeaklyTypedInput: true, KeyReplacer: keyReplacer})
proxyType, existType := mapping["type"].(string)
if !existType {
return nil, fmt.Errorf("missing type")