feat(routing): routing_profiles 表 + Profile 类型 + store(双方言)

This commit is contained in:
wangjia
2026-07-28 07:24:01 +08:00
parent c99a9b1106
commit 04b02da78d
8 changed files with 177 additions and 3 deletions
+42
View File
@@ -0,0 +1,42 @@
// Package routing holds the per-user routing profile (可配置分流): the rule
// model, persistence (Store), and — in later tasks — validation and sing-box
// config rendering.
package routing
// Rule is a single user-authored routing rule (domain/IP/geosite match →
// proxy/direct action). Validation of Type/Action/Value lives in Task 2.
type Rule struct {
Type string `json:"type"`
Value string `json:"value"`
Action string `json:"action"`
Note string `json:"note,omitempty"`
Enabled bool `json:"enabled"`
}
// Builtin toggles the built-in routing behaviors that previously were
// hardcoded into the server's sing-box config rendering.
type Builtin struct {
ChinaDirect bool `json:"china_direct"`
LanDirect bool `json:"lan_direct"`
PrivateViaTunnel bool `json:"private_via_tunnel"`
}
// Profile is a user's full routing configuration, persisted as JSON in
// routing_profiles.profile_json.
type Profile struct {
Mode string `json:"mode"` // rule | global | direct
Builtin Builtin `json:"builtin"`
Rules []Rule `json:"rules"`
Final string `json:"final"` // proxy | direct
}
// Default is the fail-safe fallback profile, equivalent to today's hardcoded
// behavior (smart routing + China direct + no user rules).
func Default() *Profile {
return &Profile{
Mode: "rule",
Builtin: Builtin{ChinaDirect: true, LanDirect: true, PrivateViaTunnel: true},
Rules: []Rule{},
Final: "proxy",
}
}