mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-04-14 20:58:33 +10:00
Add inline rule-set & Add reload for local rule-set
This commit is contained in:
@@ -17,6 +17,7 @@ type _RuleSet struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag"`
|
||||
Format string `json:"format"`
|
||||
InlineOptions PlainRuleSet `json:"-"`
|
||||
LocalOptions LocalRuleSet `json:"-"`
|
||||
RemoteOptions RemoteRuleSet `json:"-"`
|
||||
}
|
||||
@@ -26,6 +27,9 @@ type RuleSet _RuleSet
|
||||
func (r RuleSet) MarshalJSON() ([]byte, error) {
|
||||
var v any
|
||||
switch r.Type {
|
||||
case "", C.RuleSetTypeInline:
|
||||
r.Type = ""
|
||||
v = r.InlineOptions
|
||||
case C.RuleSetTypeLocal:
|
||||
v = r.LocalOptions
|
||||
case C.RuleSetTypeRemote:
|
||||
@@ -44,21 +48,26 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
||||
if r.Tag == "" {
|
||||
return E.New("missing tag")
|
||||
}
|
||||
switch r.Format {
|
||||
case "":
|
||||
return E.New("missing format")
|
||||
case C.RuleSetFormatSource, C.RuleSetFormatBinary:
|
||||
default:
|
||||
return E.New("unknown rule-set format: " + r.Format)
|
||||
if r.Type != C.RuleSetTypeInline {
|
||||
switch r.Format {
|
||||
case "":
|
||||
return E.New("missing format")
|
||||
case C.RuleSetFormatSource, C.RuleSetFormatBinary:
|
||||
default:
|
||||
return E.New("unknown rule-set format: " + r.Format)
|
||||
}
|
||||
} else {
|
||||
r.Format = ""
|
||||
}
|
||||
var v any
|
||||
switch r.Type {
|
||||
case "", C.RuleSetTypeInline:
|
||||
r.Type = C.RuleSetTypeInline
|
||||
v = &r.InlineOptions
|
||||
case C.RuleSetTypeLocal:
|
||||
v = &r.LocalOptions
|
||||
case C.RuleSetTypeRemote:
|
||||
v = &r.RemoteOptions
|
||||
case "":
|
||||
return E.New("missing type")
|
||||
default:
|
||||
return E.New("unknown rule-set type: " + r.Type)
|
||||
}
|
||||
@@ -214,15 +223,13 @@ func (r *PlainRuleSetCompat) UnmarshalJSON(bytes []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r PlainRuleSetCompat) Upgrade() PlainRuleSet {
|
||||
var result PlainRuleSet
|
||||
func (r PlainRuleSetCompat) Upgrade() (PlainRuleSet, error) {
|
||||
switch r.Version {
|
||||
case C.RuleSetVersion1, C.RuleSetVersion2:
|
||||
result = r.Options
|
||||
default:
|
||||
panic("unknown rule-set version: " + F.ToString(r.Version))
|
||||
return PlainRuleSet{}, E.New("unknown rule-set version: " + F.ToString(r.Version))
|
||||
}
|
||||
return result
|
||||
return r.Options, nil
|
||||
}
|
||||
|
||||
type PlainRuleSet struct {
|
||||
|
||||
Reference in New Issue
Block a user