mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-04 00:23:43 +08:00
chore: clean code
This commit is contained in:
parent
7b7a8981a6
commit
e0cf342672
@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/net/idna"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
@ -11,7 +10,6 @@ type Domain struct {
|
|||||||
*Base
|
*Base
|
||||||
domain string
|
domain string
|
||||||
adapter string
|
adapter string
|
||||||
isIDNA bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Domain) RuleType() C.RuleType {
|
func (d *Domain) RuleType() C.RuleType {
|
||||||
@ -27,20 +25,14 @@ func (d *Domain) Adapter() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Domain) Payload() string {
|
func (d *Domain) Payload() string {
|
||||||
domain := d.domain
|
return d.domain
|
||||||
if d.isIDNA {
|
|
||||||
domain, _ = idna.ToUnicode(domain)
|
|
||||||
}
|
|
||||||
return domain
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDomain(domain string, adapter string) *Domain {
|
func NewDomain(domain string, adapter string) *Domain {
|
||||||
actualDomain, _ := idna.ToASCII(domain)
|
|
||||||
return &Domain{
|
return &Domain{
|
||||||
Base: &Base{},
|
Base: &Base{},
|
||||||
domain: strings.ToLower(actualDomain),
|
domain: strings.ToLower(domain),
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
isIDNA: actualDomain != domain,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/net/idna"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
@ -11,7 +10,6 @@ type DomainKeyword struct {
|
|||||||
*Base
|
*Base
|
||||||
keyword string
|
keyword string
|
||||||
adapter string
|
adapter string
|
||||||
isIDNA bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dk *DomainKeyword) RuleType() C.RuleType {
|
func (dk *DomainKeyword) RuleType() C.RuleType {
|
||||||
@ -28,20 +26,14 @@ func (dk *DomainKeyword) Adapter() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dk *DomainKeyword) Payload() string {
|
func (dk *DomainKeyword) Payload() string {
|
||||||
keyword := dk.keyword
|
return dk.keyword
|
||||||
if dk.isIDNA {
|
|
||||||
keyword, _ = idna.ToUnicode(keyword)
|
|
||||||
}
|
|
||||||
return keyword
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
|
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
|
||||||
actualDomainKeyword, _ := idna.ToASCII(keyword)
|
|
||||||
return &DomainKeyword{
|
return &DomainKeyword{
|
||||||
Base: &Base{},
|
Base: &Base{},
|
||||||
keyword: strings.ToLower(actualDomainKeyword),
|
keyword: strings.ToLower(keyword),
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
isIDNA: keyword != actualDomainKeyword,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/net/idna"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
@ -11,7 +10,6 @@ type DomainSuffix struct {
|
|||||||
*Base
|
*Base
|
||||||
suffix string
|
suffix string
|
||||||
adapter string
|
adapter string
|
||||||
isIDNA bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DomainSuffix) RuleType() C.RuleType {
|
func (ds *DomainSuffix) RuleType() C.RuleType {
|
||||||
@ -28,20 +26,14 @@ func (ds *DomainSuffix) Adapter() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DomainSuffix) Payload() string {
|
func (ds *DomainSuffix) Payload() string {
|
||||||
suffix := ds.suffix
|
return ds.suffix
|
||||||
if ds.isIDNA {
|
|
||||||
suffix, _ = idna.ToUnicode(suffix)
|
|
||||||
}
|
|
||||||
return suffix
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDomainSuffix(suffix string, adapter string) *DomainSuffix {
|
func NewDomainSuffix(suffix string, adapter string) *DomainSuffix {
|
||||||
actualDomainSuffix, _ := idna.ToASCII(suffix)
|
|
||||||
return &DomainSuffix{
|
return &DomainSuffix{
|
||||||
Base: &Base{},
|
Base: &Base{},
|
||||||
suffix: strings.ToLower(actualDomainSuffix),
|
suffix: strings.ToLower(suffix),
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
isIDNA: suffix != actualDomainSuffix,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,10 +21,8 @@ func NewNetworkType(network, adapter string) (*NetworkType, error) {
|
|||||||
switch strings.ToUpper(network) {
|
switch strings.ToUpper(network) {
|
||||||
case "TCP":
|
case "TCP":
|
||||||
ntType.network = C.TCP
|
ntType.network = C.TCP
|
||||||
break
|
|
||||||
case "UDP":
|
case "UDP":
|
||||||
ntType.network = C.UDP
|
ntType.network = C.UDP
|
||||||
break
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported network type, only TCP/UDP")
|
return nil, fmt.Errorf("unsupported network type, only TCP/UDP")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user