Style: code style

This commit is contained in:
Dreamacro
2021-06-10 14:05:56 +08:00
parent 0778591524
commit 045edc188c
59 changed files with 207 additions and 220 deletions

51
rule/port.go Normal file
View File

@ -0,0 +1,51 @@
package rules
import (
"strconv"
C "github.com/Dreamacro/clash/constant"
)
type Port struct {
adapter string
port string
isSource bool
}
func (p *Port) RuleType() C.RuleType {
if p.isSource {
return C.SrcPort
}
return C.DstPort
}
func (p *Port) Match(metadata *C.Metadata) bool {
if p.isSource {
return metadata.SrcPort == p.port
}
return metadata.DstPort == p.port
}
func (p *Port) Adapter() string {
return p.adapter
}
func (p *Port) Payload() string {
return p.port
}
func (p *Port) ShouldResolveIP() bool {
return false
}
func NewPort(port string, adapter string, isSource bool) (*Port, error) {
_, err := strconv.Atoi(port)
if err != nil {
return nil, errPayload
}
return &Port{
adapter: adapter,
port: port,
isSource: isSource,
}, nil
}