mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
chore: remove unused pointer in rules implements
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type Domain struct {
|
||||
*Base
|
||||
Base
|
||||
domain string
|
||||
adapter string
|
||||
}
|
||||
@@ -32,10 +32,10 @@ func (d *Domain) Payload() string {
|
||||
func NewDomain(domain string, adapter string) *Domain {
|
||||
punycode, _ := idna.ToASCII(strings.ToLower(domain))
|
||||
return &Domain{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
domain: punycode,
|
||||
adapter: adapter,
|
||||
}
|
||||
}
|
||||
|
||||
//var _ C.Rule = (*Domain)(nil)
|
||||
var _ C.Rule = (*Domain)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type DomainKeyword struct {
|
||||
*Base
|
||||
Base
|
||||
keyword string
|
||||
adapter string
|
||||
}
|
||||
@@ -33,10 +33,10 @@ func (dk *DomainKeyword) Payload() string {
|
||||
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
|
||||
punycode, _ := idna.ToASCII(strings.ToLower(keyword))
|
||||
return &DomainKeyword{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
keyword: punycode,
|
||||
adapter: adapter,
|
||||
}
|
||||
}
|
||||
|
||||
//var _ C.Rule = (*DomainKeyword)(nil)
|
||||
var _ C.Rule = (*DomainKeyword)(nil)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type DomainRegex struct {
|
||||
*Base
|
||||
Base
|
||||
regex *regexp2.Regexp
|
||||
adapter string
|
||||
}
|
||||
@@ -36,10 +36,10 @@ func NewDomainRegex(regex string, adapter string) (*DomainRegex, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &DomainRegex{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
regex: r,
|
||||
adapter: adapter,
|
||||
}, nil
|
||||
}
|
||||
|
||||
//var _ C.Rule = (*DomainRegex)(nil)
|
||||
var _ C.Rule = (*DomainRegex)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type DomainSuffix struct {
|
||||
*Base
|
||||
Base
|
||||
suffix string
|
||||
adapter string
|
||||
}
|
||||
@@ -33,10 +33,10 @@ func (ds *DomainSuffix) Payload() string {
|
||||
func NewDomainSuffix(suffix string, adapter string) *DomainSuffix {
|
||||
punycode, _ := idna.ToASCII(strings.ToLower(suffix))
|
||||
return &DomainSuffix{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
suffix: punycode,
|
||||
adapter: adapter,
|
||||
}
|
||||
}
|
||||
|
||||
//var _ C.Rule = (*DomainSuffix)(nil)
|
||||
var _ C.Rule = (*DomainSuffix)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type DomainWildcard struct {
|
||||
*Base
|
||||
Base
|
||||
pattern string
|
||||
adapter string
|
||||
}
|
||||
@@ -34,8 +34,10 @@ var _ C.Rule = (*DomainWildcard)(nil)
|
||||
func NewDomainWildcard(pattern string, adapter string) (*DomainWildcard, error) {
|
||||
pattern = strings.ToLower(pattern)
|
||||
return &DomainWildcard{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
pattern: pattern,
|
||||
adapter: adapter,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*DomainWildcard)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type DSCP struct {
|
||||
*Base
|
||||
Base
|
||||
ranges utils.IntRanges[uint8]
|
||||
payload string
|
||||
adapter string
|
||||
@@ -41,9 +41,11 @@ func NewDSCP(dscp string, adapter string) (*DSCP, error) {
|
||||
}
|
||||
}
|
||||
return &DSCP{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
payload: dscp,
|
||||
ranges: ranges,
|
||||
adapter: adapter,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*DSCP)(nil)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type Match struct {
|
||||
*Base
|
||||
Base
|
||||
adapter string
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ func (f *Match) Payload() string {
|
||||
|
||||
func NewMatch(adapter string) *Match {
|
||||
return &Match{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
adapter: adapter,
|
||||
}
|
||||
}
|
||||
|
||||
//var _ C.Rule = (*Match)(nil)
|
||||
var _ C.Rule = (*Match)(nil)
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
type GEOIP struct {
|
||||
*Base
|
||||
Base
|
||||
country string
|
||||
adapter string
|
||||
noResolveIP bool
|
||||
@@ -205,7 +205,7 @@ func NewGEOIP(country string, adapter string, isSrc, noResolveIP bool) (*GEOIP,
|
||||
country = strings.ToLower(country)
|
||||
|
||||
geoip := &GEOIP{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
country: country,
|
||||
adapter: adapter,
|
||||
noResolveIP: noResolveIP,
|
||||
@@ -231,3 +231,5 @@ func NewGEOIP(country string, adapter string, isSrc, noResolveIP bool) (*GEOIP,
|
||||
|
||||
return geoip, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*GEOIP)(nil)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
type GEOSITE struct {
|
||||
*Base
|
||||
Base
|
||||
country string
|
||||
adapter string
|
||||
recodeSize int
|
||||
@@ -68,7 +68,7 @@ func NewGEOSITE(country string, adapter string) (*GEOSITE, error) {
|
||||
}
|
||||
|
||||
geoSite := &GEOSITE{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
country: country,
|
||||
adapter: adapter,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type InName struct {
|
||||
*Base
|
||||
Base
|
||||
names []string
|
||||
adapter string
|
||||
payload string
|
||||
@@ -46,9 +46,11 @@ func NewInName(iNames, adapter string) (*InName, error) {
|
||||
}
|
||||
|
||||
return &InName{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
names: names,
|
||||
adapter: adapter,
|
||||
payload: iNames,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*InName)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type InType struct {
|
||||
*Base
|
||||
Base
|
||||
types []C.Type
|
||||
adapter string
|
||||
payload string
|
||||
@@ -51,7 +51,7 @@ func NewInType(iTypes, adapter string) (*InType, error) {
|
||||
}
|
||||
|
||||
return &InType{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
types: tps,
|
||||
adapter: adapter,
|
||||
payload: strings.ToUpper(iTypes),
|
||||
@@ -77,3 +77,5 @@ func parseInTypes(tps []string) (res []C.Type, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var _ C.Rule = (*InType)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type InUser struct {
|
||||
*Base
|
||||
Base
|
||||
users []string
|
||||
adapter string
|
||||
payload string
|
||||
@@ -46,9 +46,11 @@ func NewInUser(iUsers, adapter string) (*InUser, error) {
|
||||
}
|
||||
|
||||
return &InUser{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
users: users,
|
||||
adapter: adapter,
|
||||
payload: iUsers,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*InUser)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type ASN struct {
|
||||
*Base
|
||||
Base
|
||||
asn string
|
||||
adapter string
|
||||
noResolveIP bool
|
||||
@@ -64,10 +64,12 @@ func NewIPASN(asn string, adapter string, isSrc, noResolveIP bool) (*ASN, error)
|
||||
}
|
||||
|
||||
return &ASN{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
asn: asn,
|
||||
adapter: adapter,
|
||||
noResolveIP: noResolveIP,
|
||||
isSourceIP: isSrc,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*ASN)(nil)
|
||||
|
||||
@@ -21,7 +21,7 @@ func WithIPCIDRNoResolve(noResolve bool) IPCIDROption {
|
||||
}
|
||||
|
||||
type IPCIDR struct {
|
||||
*Base
|
||||
Base
|
||||
ipnet netip.Prefix
|
||||
adapter string
|
||||
isSourceIP bool
|
||||
@@ -62,7 +62,7 @@ func NewIPCIDR(s string, adapter string, opts ...IPCIDROption) (*IPCIDR, error)
|
||||
}
|
||||
|
||||
ipcidr := &IPCIDR{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
ipnet: ipnet,
|
||||
adapter: adapter,
|
||||
}
|
||||
@@ -74,4 +74,4 @@ func NewIPCIDR(s string, adapter string, opts ...IPCIDROption) (*IPCIDR, error)
|
||||
return ipcidr, nil
|
||||
}
|
||||
|
||||
//var _ C.Rule = (*IPCIDR)(nil)
|
||||
var _ C.Rule = (*IPCIDR)(nil)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
"net/netip"
|
||||
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
)
|
||||
|
||||
type IPSuffix struct {
|
||||
*Base
|
||||
Base
|
||||
ipBytes []byte
|
||||
bits int
|
||||
payload string
|
||||
@@ -68,7 +69,7 @@ func NewIPSuffix(payload, adapter string, isSrc, noResolveIP bool) (*IPSuffix, e
|
||||
}
|
||||
|
||||
return &IPSuffix{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
payload: payload,
|
||||
ipBytes: ipnet.Addr().AsSlice(),
|
||||
bits: ipnet.Bits(),
|
||||
@@ -77,3 +78,5 @@ func NewIPSuffix(payload, adapter string, isSrc, noResolveIP bool) (*IPSuffix, e
|
||||
noResolveIP: noResolveIP,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*IPSuffix)(nil)
|
||||
|
||||
@@ -2,19 +2,20 @@ package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
"strings"
|
||||
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
)
|
||||
|
||||
type NetworkType struct {
|
||||
*Base
|
||||
Base
|
||||
network C.NetWork
|
||||
adapter string
|
||||
}
|
||||
|
||||
func NewNetworkType(network, adapter string) (*NetworkType, error) {
|
||||
ntType := NetworkType{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
}
|
||||
|
||||
ntType.adapter = adapter
|
||||
@@ -45,3 +46,5 @@ func (n *NetworkType) Adapter() string {
|
||||
func (n *NetworkType) Payload() string {
|
||||
return n.network.String()
|
||||
}
|
||||
|
||||
var _ C.Rule = (*NetworkType)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type Port struct {
|
||||
*Base
|
||||
Base
|
||||
adapter string
|
||||
port string
|
||||
ruleType C.RuleType
|
||||
@@ -49,7 +49,7 @@ func NewPort(port string, adapter string, ruleType C.RuleType) (*Port, error) {
|
||||
}
|
||||
|
||||
return &Port{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
adapter: adapter,
|
||||
port: port,
|
||||
ruleType: ruleType,
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type Process struct {
|
||||
*Base
|
||||
Base
|
||||
pattern string
|
||||
adapter string
|
||||
ruleType C.RuleType
|
||||
@@ -54,7 +54,7 @@ func (ps *Process) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool,
|
||||
|
||||
func NewProcess(pattern string, adapter string, ruleType C.RuleType) (*Process, error) {
|
||||
ps := &Process{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
pattern: pattern,
|
||||
adapter: adapter,
|
||||
ruleType: ruleType,
|
||||
@@ -70,3 +70,5 @@ func NewProcess(pattern string, adapter string, ruleType C.RuleType) (*Process,
|
||||
}
|
||||
return ps, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*Process)(nil)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type Uid struct {
|
||||
*Base
|
||||
Base
|
||||
uids utils.IntRanges[uint32]
|
||||
oUid string
|
||||
adapter string
|
||||
@@ -30,7 +30,7 @@ func NewUid(oUid, adapter string) (*Uid, error) {
|
||||
return nil, errPayload
|
||||
}
|
||||
return &Uid{
|
||||
Base: &Base{},
|
||||
Base: Base{},
|
||||
adapter: adapter,
|
||||
oUid: oUid,
|
||||
uids: uidRange,
|
||||
@@ -61,3 +61,5 @@ func (u *Uid) Adapter() string {
|
||||
func (u *Uid) Payload() string {
|
||||
return u.oUid
|
||||
}
|
||||
|
||||
var _ C.Rule = (*Uid)(nil)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type Logic struct {
|
||||
*common.Base
|
||||
common.Base
|
||||
payload string
|
||||
adapter string
|
||||
ruleType C.RuleType
|
||||
@@ -24,7 +24,7 @@ type Logic struct {
|
||||
}
|
||||
|
||||
func NewSubRule(payload, adapter string, subRules map[string][]C.Rule, parseRule common.ParseRuleFunc) (*Logic, error) {
|
||||
logic := &Logic{Base: &common.Base{}, payload: payload, adapter: adapter, ruleType: C.SubRules, subRules: subRules}
|
||||
logic := &Logic{Base: common.Base{}, payload: payload, adapter: adapter, ruleType: C.SubRules, subRules: subRules}
|
||||
err := logic.parsePayload(fmt.Sprintf("(%s)", payload), parseRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -37,7 +37,7 @@ func NewSubRule(payload, adapter string, subRules map[string][]C.Rule, parseRule
|
||||
}
|
||||
|
||||
func NewNOT(payload string, adapter string, parseRule common.ParseRuleFunc) (*Logic, error) {
|
||||
logic := &Logic{Base: &common.Base{}, payload: payload, adapter: adapter, ruleType: C.NOT}
|
||||
logic := &Logic{Base: common.Base{}, payload: payload, adapter: adapter, ruleType: C.NOT}
|
||||
err := logic.parsePayload(payload, parseRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -50,7 +50,7 @@ func NewNOT(payload string, adapter string, parseRule common.ParseRuleFunc) (*Lo
|
||||
}
|
||||
|
||||
func NewOR(payload string, adapter string, parseRule common.ParseRuleFunc) (*Logic, error) {
|
||||
logic := &Logic{Base: &common.Base{}, payload: payload, adapter: adapter, ruleType: C.OR}
|
||||
logic := &Logic{Base: common.Base{}, payload: payload, adapter: adapter, ruleType: C.OR}
|
||||
err := logic.parsePayload(payload, parseRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -59,7 +59,7 @@ func NewOR(payload string, adapter string, parseRule common.ParseRuleFunc) (*Log
|
||||
}
|
||||
|
||||
func NewAND(payload string, adapter string, parseRule common.ParseRuleFunc) (*Logic, error) {
|
||||
logic := &Logic{Base: &common.Base{}, payload: payload, adapter: adapter, ruleType: C.AND}
|
||||
logic := &Logic{Base: common.Base{}, payload: payload, adapter: adapter, ruleType: C.AND}
|
||||
err := logic.parsePayload(payload, parseRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -265,3 +265,5 @@ func (logic *Logic) ProviderNames() (names []string) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var _ C.Rule = (*Logic)(nil)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type RuleSet struct {
|
||||
*common.Base
|
||||
common.Base
|
||||
ruleProviderName string
|
||||
adapter string
|
||||
isSrc bool
|
||||
@@ -66,7 +66,7 @@ func (rs *RuleSet) getProvider() (P.RuleProvider, bool) {
|
||||
|
||||
func NewRuleSet(ruleProviderName string, adapter string, isSrc bool, noResolveIP bool) (*RuleSet, error) {
|
||||
rs := &RuleSet{
|
||||
Base: &common.Base{},
|
||||
Base: common.Base{},
|
||||
ruleProviderName: ruleProviderName,
|
||||
adapter: adapter,
|
||||
isSrc: isSrc,
|
||||
@@ -74,3 +74,5 @@ func NewRuleSet(ruleProviderName string, adapter string, isSrc bool, noResolveIP
|
||||
}
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
var _ C.Rule = (*RuleSet)(nil)
|
||||
|
||||
Reference in New Issue
Block a user