-
Notifications
You must be signed in to change notification settings - Fork 37
/
template.go
137 lines (116 loc) · 5.81 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package option
import (
C "github.com/sagernet/serenity/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-dns"
"github.com/sagernet/sing/common/json"
)
type _Template struct {
RawMessage json.RawMessage `json:"-"`
Name string `json:"name,omitempty"`
Extend string `json:"extend,omitempty"`
// Global
Log *option.LogOptions `json:"log,omitempty"`
DomainStrategy option.DomainStrategy `json:"domain_strategy,omitempty"`
DisableTrafficBypass bool `json:"disable_traffic_bypass,omitempty"`
DisableRuleSet bool `json:"disable_rule_set,omitempty"`
RemoteResolve bool `json:"remote_resolve,omitempty"`
// DNS
DNSDefault string `json:"dns_default,omitempty"`
DNSLocal string `json:"dns_local,omitempty"`
EnableFakeIP bool `json:"enable_fakeip,omitempty"`
DisableDNSLeak bool `json:"disable_dns_leak,omitempty"`
PreDNSRules []option.DNSRule `json:"pre_dns_rules,omitempty"`
CustomDNSRules []option.DNSRule `json:"custom_dns_rules,omitempty"`
// Inbound
Inbounds []option.Inbound `json:"inbounds,omitempty"`
AutoRedirect bool `json:"auto_redirect,omitempty"`
DisableTUN bool `json:"disable_tun,omitempty"`
DisableSystemProxy bool `json:"disable_system_proxy,omitempty"`
CustomTUN *TypedMessage[option.TunInboundOptions] `json:"custom_tun,omitempty"`
CustomMixed *TypedMessage[option.HTTPMixedInboundOptions] `json:"custom_mixed,omitempty"`
// Outbound
ExtraGroups []ExtraGroup `json:"extra_groups,omitempty"`
GenerateGlobalURLTest bool `json:"generate_global_urltest,omitempty"`
DirectTag string `json:"direct_tag,omitempty"`
BlockTag string `json:"block_tag,omitempty"`
DefaultTag string `json:"default_tag,omitempty"`
URLTestTag string `json:"urltest_tag,omitempty"`
CustomDirect *option.DirectOutboundOptions `json:"custom_direct,omitempty"`
CustomSelector *option.SelectorOutboundOptions `json:"custom_selector,omitempty"`
CustomURLTest *option.URLTestOutboundOptions `json:"custom_urltest,omitempty"`
// Route
DisableDefaultRules bool `json:"disable_default_rules,omitempty"`
PreRules []option.Rule `json:"pre_rules,omitempty"`
CustomRules []option.Rule `json:"custom_rules,omitempty"`
EnableJSDelivr bool `json:"enable_jsdelivr,omitempty"`
CustomGeoIP *option.GeoIPOptions `json:"custom_geoip,omitempty"`
CustomGeosite *option.GeositeOptions `json:"custom_geosite,omitempty"`
CustomRuleSet []RuleSet `json:"custom_rule_set,omitempty"`
PostRuleSet []RuleSet `json:"post_rule_set,omitempty"`
// Experimental
DisableCacheFile bool `json:"disable_cache_file,omitempty"`
DisableExternalController bool `json:"disable_external_controller,omitempty"`
DisableClashMode bool `json:"disable_clash_mode,omitempty"`
ClashModeLeak string `json:"clash_mode_leak,omitempty"`
ClashModeRule string `json:"clash_mode_rule,omitempty"`
ClashModeGlobal string `json:"clash_mode_global,omitempty"`
ClashModeDirect string `json:"clash_mode_direct,omitempty"`
CustomClashAPI *TypedMessage[option.ClashAPIOptions] `json:"custom_clash_api,omitempty"`
// Debug
PProfListen string `json:"pprof_listen,omitempty"`
MemoryLimit option.MemoryBytes `json:"memory_limit,omitempty"`
}
type Template _Template
func (t *Template) MarshalJSON() ([]byte, error) {
return json.Marshal((*_Template)(t))
}
func (t *Template) UnmarshalJSON(bytes []byte) error {
err := json.Unmarshal(bytes, (*_Template)(t))
if err != nil {
return err
}
t.RawMessage = bytes
return nil
}
type _RuleSet struct {
Type string `json:"type,omitempty"`
DefaultOptions option.RuleSet `json:"-"`
GitHubOptions GitHubRuleSetOptions `json:"-"`
}
type RuleSet _RuleSet
func (r *RuleSet) MarshalJSON() ([]byte, error) {
if r.Type == C.RuleSetTypeGitHub {
return option.MarshallObjects((*_RuleSet)(r), r.GitHubOptions)
} else {
return json.Marshal(r.DefaultOptions)
}
}
func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
err := json.Unmarshal(bytes, (*_RuleSet)(r))
if err != nil {
return err
}
if r.Type == C.RuleSetTypeGitHub {
return option.UnmarshallExcluded(bytes, (*_RuleSet)(r), &r.GitHubOptions)
} else {
return json.Unmarshal(bytes, &r.DefaultOptions)
}
}
type GitHubRuleSetOptions struct {
Repository string `json:"repository,omitempty"`
Path string `json:"path,omitempty"`
Prefix string `json:"prefix,omitempty"`
RuleSet option.Listable[string] `json:"rule_set,omitempty"`
}
func (t Template) DisableIPv6() bool {
return t.DomainStrategy == option.DomainStrategy(dns.DomainStrategyUseIPv4)
}
type ExtraGroup struct {
Tag string `json:"tag,omitempty"`
Type string `json:"type,omitempty"`
Filter option.Listable[string] `json:"filter,omitempty"`
Exclude option.Listable[string] `json:"exclude,omitempty"`
CustomSelector *option.SelectorOutboundOptions `json:"custom_selector,omitempty"`
CustomURLTest *option.URLTestOutboundOptions `json:"custom_urltest,omitempty"`
}