Files
pangolin/server/internal/routing/profile.go
T

43 lines
1.4 KiB
Go

// 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",
}
}