remove duplicate code

This commit is contained in:
zu1k
2020-08-17 09:17:39 +08:00
parent a29d02c88e
commit 12da2a73d6
6 changed files with 19 additions and 40 deletions

View File

@@ -36,7 +36,7 @@ func (c Clash) Provide() string {
for _, p := range c.Proxies {
if checkClashSupport(p) {
for _, t := range types {
if p.Type() == t {
if p.TypeName() == t {
resultBuilder.WriteString(p.ToClash() + "\n")
}
}
@@ -48,7 +48,7 @@ func (c Clash) Provide() string {
}
func checkClashSupport(p proxy.Proxy) bool {
switch p.Type() {
switch p.TypeName() {
case "ssr":
ssr := p.(*proxy.ShadowsocksR)
if checkInList(ssrCipherList, ssr.Cipher) && checkInList(ssrProtocolList, ssr.Protocol) && checkInList(ssrObfsList, ssr.Obfs) {

View File

@@ -8,13 +8,28 @@ type Base struct {
UDP bool `yaml:"udp,omitempty" json:"udp,omitempty"`
}
func (b *Base) TypeName() string {
if b.Type == "" {
return "unknown"
}
return b.Type
}
func (b *Base) SetName(name string) {
b.Name = name
}
func (b *Base) BaseInfo() *Base {
return b
}
type Proxy interface {
String() string
ToClash() string
ToSurge() string
Identifier() string
SetName(name string)
Type() string
TypeName() string
BaseInfo() *Base
}

View File

@@ -19,7 +19,7 @@ func testDelay(p Proxy) (delay uint16, err error) {
}
pmap["port"] = int(pmap["port"].(float64))
if p.Type() == "vmess" {
if p.TypeName() == "vmess" {
pmap["alterId"] = int(pmap["alterId"].(float64))
}

View File

@@ -61,18 +61,6 @@ func (ss Shadowsocks) ToSurge() string {
}
}
func (ss *Shadowsocks) SetName(name string) {
ss.Name = name
}
func (ss *Shadowsocks) Type() string {
return "ss"
}
func (ss *Shadowsocks) BaseInfo() *Base {
return &ss.Base
}
func ParseSSLink(link string) (*Shadowsocks, error) {
if !strings.HasPrefix(link, "ss://") {
return nil, ErrorNotSSRLink

View File

@@ -57,18 +57,6 @@ func (ssr ShadowsocksR) ToSurge() string {
return ""
}
func (ssr *ShadowsocksR) SetName(name string) {
ssr.Name = name
}
func (ssr *ShadowsocksR) Type() string {
return "ssr"
}
func (ssr *ShadowsocksR) BaseInfo() *Base {
return &ssr.Base
}
func ParseSSRLink(link string) (*ShadowsocksR, error) {
if !strings.HasPrefix(link, "ssr") {
return nil, ErrorNotSSRLink

View File

@@ -82,18 +82,6 @@ func (v Vmess) ToSurge() string {
}
}
func (v *Vmess) SetName(name string) {
v.Name = name
}
func (v *Vmess) Type() string {
return "vmess"
}
func (v *Vmess) BaseInfo() *Base {
return &v.Base
}
type vmessLinkJson struct {
Add string `json:"add"`
V string `json:"v"`