From b18a33552c9da6eb94b04f680e4382cf73ae7a81 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Tue, 6 Jan 2026 09:29:09 +0800 Subject: [PATCH] chore: remove unused pointer in rules implements --- rules/common/domain.go | 6 +++--- rules/common/domain_keyword.go | 6 +++--- rules/common/domain_regex.go | 6 +++--- rules/common/domain_suffix.go | 6 +++--- rules/common/domain_wildcard.go | 6 ++++-- rules/common/dscp.go | 6 ++++-- rules/common/final.go | 6 +++--- rules/common/geoip.go | 6 ++++-- rules/common/geosite.go | 4 ++-- rules/common/in_name.go | 6 ++++-- rules/common/in_type.go | 6 ++++-- rules/common/in_user.go | 6 ++++-- rules/common/ipasn.go | 6 ++++-- rules/common/ipcidr.go | 6 +++--- rules/common/ipsuffix.go | 9 ++++++--- rules/common/network_type.go | 9 ++++++--- rules/common/port.go | 4 ++-- rules/common/process.go | 6 ++++-- rules/common/uid.go | 6 ++++-- rules/logic/logic.go | 12 +++++++----- rules/provider/rule_set.go | 6 ++++-- 21 files changed, 81 insertions(+), 53 deletions(-) diff --git a/rules/common/domain.go b/rules/common/domain.go index 7feb6a19..c5bf2b88 100644 --- a/rules/common/domain.go +++ b/rules/common/domain.go @@ -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) diff --git a/rules/common/domain_keyword.go b/rules/common/domain_keyword.go index 813e07a0..435c6449 100644 --- a/rules/common/domain_keyword.go +++ b/rules/common/domain_keyword.go @@ -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) diff --git a/rules/common/domain_regex.go b/rules/common/domain_regex.go index 62957b4b..de1662fa 100644 --- a/rules/common/domain_regex.go +++ b/rules/common/domain_regex.go @@ -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) diff --git a/rules/common/domain_suffix.go b/rules/common/domain_suffix.go index 54c32014..12c29550 100644 --- a/rules/common/domain_suffix.go +++ b/rules/common/domain_suffix.go @@ -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) diff --git a/rules/common/domain_wildcard.go b/rules/common/domain_wildcard.go index 3dc38932..8a5b4539 100644 --- a/rules/common/domain_wildcard.go +++ b/rules/common/domain_wildcard.go @@ -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) diff --git a/rules/common/dscp.go b/rules/common/dscp.go index f3dcca8a..bd776641 100644 --- a/rules/common/dscp.go +++ b/rules/common/dscp.go @@ -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) diff --git a/rules/common/final.go b/rules/common/final.go index 92c46c7b..e6ffca46 100644 --- a/rules/common/final.go +++ b/rules/common/final.go @@ -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) diff --git a/rules/common/geoip.go b/rules/common/geoip.go index bf4b56af..26a2c42b 100644 --- a/rules/common/geoip.go +++ b/rules/common/geoip.go @@ -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) diff --git a/rules/common/geosite.go b/rules/common/geosite.go index f61d68a8..58e0217e 100644 --- a/rules/common/geosite.go +++ b/rules/common/geosite.go @@ -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, } diff --git a/rules/common/in_name.go b/rules/common/in_name.go index 87965c70..4750dabc 100644 --- a/rules/common/in_name.go +++ b/rules/common/in_name.go @@ -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) diff --git a/rules/common/in_type.go b/rules/common/in_type.go index 830136e0..a982ba9c 100644 --- a/rules/common/in_type.go +++ b/rules/common/in_type.go @@ -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) diff --git a/rules/common/in_user.go b/rules/common/in_user.go index a38fdb62..77f7ed99 100644 --- a/rules/common/in_user.go +++ b/rules/common/in_user.go @@ -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) diff --git a/rules/common/ipasn.go b/rules/common/ipasn.go index 6adefd05..651cb7c9 100644 --- a/rules/common/ipasn.go +++ b/rules/common/ipasn.go @@ -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) diff --git a/rules/common/ipcidr.go b/rules/common/ipcidr.go index 88d6ccc5..c8e0cb06 100644 --- a/rules/common/ipcidr.go +++ b/rules/common/ipcidr.go @@ -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) diff --git a/rules/common/ipsuffix.go b/rules/common/ipsuffix.go index 98f07acd..a1c7a11b 100644 --- a/rules/common/ipsuffix.go +++ b/rules/common/ipsuffix.go @@ -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) diff --git a/rules/common/network_type.go b/rules/common/network_type.go index d7003cd8..91001542 100644 --- a/rules/common/network_type.go +++ b/rules/common/network_type.go @@ -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) diff --git a/rules/common/port.go b/rules/common/port.go index 3e9d8806..42facdc5 100644 --- a/rules/common/port.go +++ b/rules/common/port.go @@ -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, diff --git a/rules/common/process.go b/rules/common/process.go index f10fc5c5..77c7b0e3 100644 --- a/rules/common/process.go +++ b/rules/common/process.go @@ -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) diff --git a/rules/common/uid.go b/rules/common/uid.go index 31365c9b..535565c5 100644 --- a/rules/common/uid.go +++ b/rules/common/uid.go @@ -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) diff --git a/rules/logic/logic.go b/rules/logic/logic.go index e4f3817e..7e43932e 100644 --- a/rules/logic/logic.go +++ b/rules/logic/logic.go @@ -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) diff --git a/rules/provider/rule_set.go b/rules/provider/rule_set.go index 320307e7..13ea323a 100644 --- a/rules/provider/rule_set.go +++ b/rules/provider/rule_set.go @@ -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)