feat: add readable routing rule comments
This commit is contained in:
1 parent
2206d03b39
commit
2fcb4ae171
4 files changed
+25
No files matched your search
@@ -18,6 +18,7 @@ go run . -config config.yaml
|
||||
`tokenEnv` задаёт имя переменной окружения и имеет приоритет над непустым `token`.
|
||||
|
||||
- `disabled: true` записывает в правило `enabled: false`; правило остаётся в конфигурации.
|
||||
- `comment` задаёт отображаемое в 3x-ui имя правила; по умолчанию используется `name`.
|
||||
- Один совпавший `outbound.tag` используется напрямую; несколько создают балансировщик.
|
||||
- `leastPing` и `leastLoad` требуют Xray `observatory`.
|
||||
- Порядок правил в YAML сохраняется; `sync.position` выбирает размещение блока: `first` или `last`.
|
||||
@@ -40,6 +41,7 @@ go run . -config config.yaml
|
||||
`tokenEnv` names an environment variable and overrides a non-empty `token`.
|
||||
|
||||
- `disabled: true` writes `enabled: false` to the rule while retaining it in configuration.
|
||||
- `comment` sets the rule name displayed in 3x-ui; it defaults to `name`.
|
||||
- One matching `outbound.tag` is used directly; several matches create a balancer.
|
||||
- `leastPing` and `leastLoad` require an Xray `observatory`.
|
||||
- YAML rule order is retained; `sync.position` places the managed block at `first` or `last`.
|
||||
|
||||
@@ -7,6 +7,8 @@ servers:
|
||||
|
||||
rules:
|
||||
- name: google
|
||||
# Displayed as the rule name in 3x-ui. Defaults to `name` when omitted.
|
||||
comment: Google
|
||||
# disabled: true # writes enabled: false in the Xray rule
|
||||
match:
|
||||
domain: [geosite:google]
|
||||
|
||||
@@ -38,6 +38,7 @@ type Server struct {
|
||||
|
||||
type Rule struct {
|
||||
Name string `yaml:"name"`
|
||||
Comment string `yaml:"comment"`
|
||||
Disabled bool `yaml:"disabled"`
|
||||
Match map[string]any `yaml:"match"`
|
||||
Outbound Outbound `yaml:"outbound"`
|
||||
@@ -335,7 +336,12 @@ func reconcileWithOutbounds(config map[string]any, desired []Rule, position stri
|
||||
delete(item, "outboundTag")
|
||||
delete(item, "balancerTag")
|
||||
delete(item, "ruleTag")
|
||||
delete(item, "comment")
|
||||
item["ruleTag"] = managedPrefix + rule.Name
|
||||
item["comment"] = rule.Comment
|
||||
if rule.Comment == "" {
|
||||
item["comment"] = rule.Name
|
||||
}
|
||||
item["enabled"] = !rule.Disabled
|
||||
if len(matches) == 1 {
|
||||
item["outboundTag"] = matches[0]
|
||||
|
||||
@@ -69,3 +69,18 @@ func TestDisabledRuleWritesEnabledFalse(t *testing.T) {
|
||||
t.Fatalf("disabled rule: %#v", rules)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReconcileWritesRuleComment(t *testing.T) {
|
||||
config := map[string]any{"outbounds": []any{map[string]any{"tag": "proxy-a"}}}
|
||||
updated, err := reconcile(config, []Rule{
|
||||
{Name: "clash-royale", Comment: "Clash Royale", Match: map[string]any{"comment": "ignored"}, Outbound: Outbound{TagRegex: "proxy-a"}},
|
||||
{Name: "ip-rules", Outbound: Outbound{TagRegex: "proxy-a"}},
|
||||
}, "last")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rules, _ := objects(updated["routing"].(map[string]any)["rules"])
|
||||
if rules[0]["comment"] != "Clash Royale" || rules[1]["comment"] != "ip-rules" {
|
||||
t.Fatalf("unexpected comments: %#v", rules)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user