Skip to content

Commit 218c3b4

Browse files
authored
Refactor(constant): added rule string enums in configs as RuleConfig for better outside integrations (#2878)
1 parent cb8c732 commit 218c3b4

File tree

16 files changed

+249
-16
lines changed

16 files changed

+249
-16
lines changed

.golangci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ linters:
1111
- unconvert
1212
- unused
1313
- usestdlibvars
14+
- exhaustive
1415

1516
linters-settings:
1617
gci:
@@ -21,3 +22,5 @@ linters-settings:
2122
- default
2223
staticcheck:
2324
go: '1.21'
25+
exhaustive:
26+
default-signifies-exhaustive: true

constant/metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func (t Type) String() string {
5252
return "Redir"
5353
case TPROXY:
5454
return "TProxy"
55+
case TUNNEL:
56+
return "Tunnel"
5557
default:
5658
return "Unknown"
5759
}

constant/rule.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
package constant
22

3+
const (
4+
RuleConfigDomain RuleConfig = "DOMAIN"
5+
RuleConfigDomainSuffix RuleConfig = "DOMAIN-SUFFIX"
6+
RuleConfigDomainKeyword RuleConfig = "DOMAIN-KEYWORD"
7+
RuleConfigGeoIP RuleConfig = "GEOIP"
8+
RuleConfigIPCIDR RuleConfig = "IP-CIDR"
9+
RuleConfigIPCIDR6 RuleConfig = "IP-CIDR6"
10+
RuleConfigSrcIPCIDR RuleConfig = "SRC-IP-CIDR"
11+
RuleConfigSrcPort RuleConfig = "SRC-PORT"
12+
RuleConfigDstPort RuleConfig = "DST-PORT"
13+
RuleConfigInboundPort RuleConfig = "INBOUND-PORT"
14+
RuleConfigProcessName RuleConfig = "PROCESS-NAME"
15+
RuleConfigProcessPath RuleConfig = "PROCESS-PATH"
16+
RuleConfigIPSet RuleConfig = "IPSET"
17+
RuleConfigRuleSet RuleConfig = "RULE-SET"
18+
RuleConfigScript RuleConfig = "SCRIPT"
19+
RuleConfigMatch RuleConfig = "MATCH"
20+
)
21+
22+
// Rule Config Type String represents a rule type in configuration files.
23+
type RuleConfig string
24+
325
// Rule Type
426
const (
527
Domain RuleType = iota

log/log.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func print(data Event) {
8888
log.Errorln(data.Payload)
8989
case DEBUG:
9090
log.Debugln(data.Payload)
91+
case SILENT:
92+
return
9193
}
9294
}
9395

rule/domain.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
C "github.com/Dreamacro/clash/constant"
77
)
88

9+
// Implements C.Rule
10+
var _ C.Rule = (*Domain)(nil)
11+
912
type Domain struct {
1013
domain string
1114
adapter string

rule/domain_keyword.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
C "github.com/Dreamacro/clash/constant"
77
)
88

9+
// Implements C.Rule
10+
var _ C.Rule = (*DomainKeyword)(nil)
11+
912
type DomainKeyword struct {
1013
keyword string
1114
adapter string

rule/domain_suffix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
C "github.com/Dreamacro/clash/constant"
77
)
88

9+
// Implements C.Rule
10+
var _ C.Rule = (*DomainSuffix)(nil)
11+
912
type DomainSuffix struct {
1013
suffix string
1114
adapter string

rule/final.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
C "github.com/Dreamacro/clash/constant"
55
)
66

7+
// Implements C.Rule
8+
var _ C.Rule = (*Match)(nil)
9+
710
type Match struct {
811
adapter string
912
}

rule/geoip.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
C "github.com/Dreamacro/clash/constant"
88
)
99

10+
// Implements C.Rule
11+
var _ C.Rule = (*GEOIP)(nil)
12+
1013
type GEOIP struct {
1114
country string
1215
adapter string

rule/ipcidr.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func WithIPCIDRNoResolve(noResolve bool) IPCIDROption {
2020
}
2121
}
2222

23+
// Implements C.Rule
24+
var _ C.Rule = (*IPCIDR)(nil)
25+
2326
type IPCIDR struct {
2427
ipnet *net.IPNet
2528
adapter string

0 commit comments

Comments
 (0)