Refactor proxy structure and parser implementations to streamline protocol handling; remove unused marshaler interfaces and improve YAML serialization for various proxy types.

This commit is contained in:
2025-06-12 10:27:22 +10:00
parent 2d8508f390
commit cdf69ce65f
23 changed files with 235 additions and 548 deletions

View File

@ -80,13 +80,15 @@ func (p *AnytlsParser) Parse(proxy string) (P.Proxy, error) {
remarks = strings.TrimSpace(remarks)
result := P.Proxy{
Type: p.GetType(),
Name: remarks,
Server: server,
Port: port,
Password: password,
Sni: sni,
SkipCertVerify: insecureBool,
Type: p.GetType(),
Name: remarks,
Anytls: P.Anytls{
Server: server,
Port: port,
Password: password,
Sni: sni,
SkipCertVerify: insecureBool,
},
}
return result, nil
}

View File

@ -89,18 +89,20 @@ func (p *HysteriaParser) Parse(proxy string) (P.Proxy, error) {
remarks = strings.TrimSpace(remarks)
result := P.Proxy{
Type: p.GetType(),
Name: remarks,
Server: server,
Port: port,
Up: upmbps,
Down: downmbps,
Auth: auth,
Obfs: obfs,
SkipCertVerify: insecureBool,
Alpn: alpn,
Protocol: protocol,
AllowInsecure: insecureBool,
Type: p.GetType(),
Name: remarks,
Hysteria: P.Hysteria{
Server: server,
Port: port,
Up: upmbps,
Down: downmbps,
Auth: auth,
Obfs: obfs,
SkipCertVerify: insecureBool,
Alpn: alpn,
Protocol: protocol,
AllowInsecure: insecureBool,
},
}
return result, nil
}

View File

@ -81,17 +81,19 @@ func (p *Hysteria2Parser) Parse(proxy string) (P.Proxy, error) {
remarks = strings.TrimSpace(remarks)
result := P.Proxy{
Type: p.GetType(),
Name: remarks,
Server: server,
Port: port,
Password: password,
Obfs: obfs,
ObfsParam: obfsPassword,
Sni: sni,
SkipCertVerify: insecureBool,
TLS: enableTLS,
Network: network,
Type: p.GetType(),
Name: remarks,
Hysteria2: P.Hysteria2{
Server: server,
Port: port,
Password: password,
Obfs: obfs,
ObfsParam: obfsPassword,
Sni: sni,
SkipCertVerify: insecureBool,
TLS: enableTLS,
Network: network,
},
}
return result, nil
}

View File

@ -123,12 +123,14 @@ func (p *ShadowsocksParser) Parse(proxy string) (P.Proxy, error) {
remarks = strings.TrimSpace(remarks)
result := P.Proxy{
Type: p.GetType(),
Cipher: method,
Password: password,
Server: server,
Port: port,
Name: remarks,
Type: p.GetType(),
Name: remarks,
ShadowSocks: P.ShadowSocks{
Cipher: method,
Password: password,
Server: server,
Port: port,
},
}
return result, nil

View File

@ -102,16 +102,18 @@ func (p *ShadowsocksRParser) Parse(proxy string) (P.Proxy, error) {
}
result := P.Proxy{
Name: remarks,
Type: p.GetType(),
Server: server,
Port: port,
Protocol: protocol,
Cipher: method,
Obfs: obfs,
Password: password,
ObfsParam: obfsParam,
ProtocolParam: protoParam,
Type: p.GetType(),
Name: remarks,
ShadowSocksR: P.ShadowSocksR{
Server: server,
Port: port,
Protocol: protocol,
Cipher: method,
Obfs: obfs,
Password: password,
ObfsParam: obfsParam,
ProtocolParam: protoParam,
},
}
return result, nil

View File

@ -87,12 +87,14 @@ func (p *SocksParser) Parse(proxy string) (P.Proxy, error) {
}
}
return P.Proxy{
Type: p.GetType(),
Name: remarks,
Server: server,
Port: port,
Username: username,
Password: password,
Type: p.GetType(),
Name: remarks,
Socks: P.Socks{
Server: server,
Port: port,
Username: username,
Password: password,
},
}, nil
}

View File

@ -84,12 +84,10 @@ func (p *TrojanParser) Parse(proxy string) (P.Proxy, error) {
alpn = nil
}
result := P.Proxy{
Type: p.GetType(),
result := P.Trojan{
Server: server,
Port: port,
Password: password,
Name: remarks,
Network: network,
}
@ -125,7 +123,11 @@ func (p *TrojanParser) Parse(proxy string) (P.Proxy, error) {
}
}
return result, nil
return P.Proxy{
Type: p.GetType(),
Name: remarks,
Trojan: result,
}, nil
}
func init() {

View File

@ -76,10 +76,8 @@ func (p *VlessParser) Parse(proxy string) (P.Proxy, error) {
}
remarks = strings.TrimSpace(remarks)
result := P.Proxy{
Type: p.GetType(),
result := P.Vless{
Server: server,
Name: remarks,
Port: port,
UUID: uuid,
Flow: flow,
@ -141,7 +139,11 @@ func (p *VlessParser) Parse(proxy string) (P.Proxy, error) {
}
}
return result, nil
return P.Proxy{
Type: p.GetType(),
Name: remarks,
Vless: result,
}, nil
}
func init() {

View File

@ -10,6 +10,24 @@ import (
P "github.com/bestnite/sub2clash/model/proxy"
)
type VmessJson struct {
V any `json:"v"`
Ps string `json:"ps"`
Add string `json:"add"`
Port any `json:"port"`
Id string `json:"id"`
Aid any `json:"aid"`
Scy string `json:"scy"`
Net string `json:"net"`
Type string `json:"type"`
Host string `json:"host"`
Path string `json:"path"`
Tls string `json:"tls"`
Sni string `json:"sni"`
Alpn string `json:"alpn"`
Fp string `json:"fp"`
}
type VmessParser struct{}
func (p *VmessParser) SupportClash() bool {
@ -44,7 +62,7 @@ func (p *VmessParser) Parse(proxy string) (P.Proxy, error) {
return P.Proxy{}, &E.ParseError{Type: E.ErrInvalidBase64, Raw: proxy, Message: err.Error()}
}
var vmess P.VmessJson
var vmess VmessJson
err = json.Unmarshal([]byte(base64), &vmess)
if err != nil {
return P.Proxy{}, &E.ParseError{Type: E.ErrInvalidStruct, Raw: proxy, Message: err.Error()}
@ -85,9 +103,7 @@ func (p *VmessParser) Parse(proxy string) (P.Proxy, error) {
name = vmess.Ps
}
result := P.Proxy{
Name: name,
Type: p.GetType(),
result := P.Vmess{
Server: vmess.Add,
Port: port,
UUID: vmess.Id,
@ -139,7 +155,11 @@ func (p *VmessParser) Parse(proxy string) (P.Proxy, error) {
result.Network = "h2"
}
return result, nil
return P.Proxy{
Type: p.GetType(),
Name: name,
Vmess: result,
}, nil
}
func init() {