mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-14 14:09:22 +00:00
chore: code cleanup
This commit is contained in:
@@ -90,6 +90,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||
}
|
||||
}
|
||||
|
||||
updateExperimental(cfg)
|
||||
updateUsers(cfg.Users)
|
||||
updateProxies(cfg.Proxies, cfg.Providers)
|
||||
updateRules(cfg.Rules, cfg.SubRules, cfg.RuleProviders)
|
||||
@@ -100,8 +101,6 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||
updateDNS(cfg.DNS, cfg.General.IPv6)
|
||||
updateListeners(cfg.General, cfg.Listeners, force)
|
||||
updateIPTables(cfg)
|
||||
updateTun(cfg.General)
|
||||
updateExperimental(cfg)
|
||||
updateTunnels(cfg.Tunnels)
|
||||
|
||||
tunnel.OnInnerLoading()
|
||||
@@ -186,6 +185,7 @@ func updateListeners(general *config.General, listeners map[string]C.InboundList
|
||||
listener.ReCreateShadowSocks(general.ShadowSocksConfig, tunnel.Tunnel)
|
||||
listener.ReCreateVmess(general.VmessConfig, tunnel.Tunnel)
|
||||
listener.ReCreateTuic(general.TuicServer, tunnel.Tunnel)
|
||||
listener.ReCreateTun(general.Tun, tunnel.Tunnel)
|
||||
}
|
||||
|
||||
func updateExperimental(c *config.Config) {
|
||||
@@ -343,12 +343,6 @@ func hcCompatibleProvider(proxyProviders map[string]provider.ProxyProvider) {
|
||||
}
|
||||
|
||||
}
|
||||
func updateTun(general *config.General) {
|
||||
if general == nil {
|
||||
return
|
||||
}
|
||||
listener.ReCreateTun(general.Tun, tunnel.Tunnel)
|
||||
}
|
||||
|
||||
func updateSniffer(sniffer *config.Sniffer) {
|
||||
if sniffer.Enable {
|
||||
|
||||
@@ -62,7 +62,6 @@ type tunSchema struct {
|
||||
DNSHijack *[]string `yaml:"dns-hijack" json:"dns-hijack"`
|
||||
AutoRoute *bool `yaml:"auto-route" json:"auto-route"`
|
||||
AutoDetectInterface *bool `yaml:"auto-detect-interface" json:"auto-detect-interface"`
|
||||
//RedirectToTun []string `yaml:"-" json:"-"`
|
||||
|
||||
MTU *uint32 `yaml:"mtu" json:"mtu,omitempty"`
|
||||
GSO *bool `yaml:"gso" json:"gso,omitempty"`
|
||||
@@ -118,21 +117,13 @@ func getConfigs(w http.ResponseWriter, r *http.Request) {
|
||||
render.JSON(w, r, general)
|
||||
}
|
||||
|
||||
func pointerOrDefault(p *int, def int) int {
|
||||
func pointerOrDefault[T any](p *T, def T) T {
|
||||
if p != nil {
|
||||
return *p
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func pointerOrDefaultString(p *string, def string) string {
|
||||
if p != nil {
|
||||
return *p
|
||||
}
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
func pointerOrDefaultTun(p *tunSchema, def LC.Tun) LC.Tun {
|
||||
if p != nil {
|
||||
def.Enable = p.Enable
|
||||
@@ -336,8 +327,8 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
||||
P.ReCreateTProxy(pointerOrDefault(general.TProxyPort, ports.TProxyPort), tunnel.Tunnel)
|
||||
P.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tunnel.Tunnel)
|
||||
P.ReCreateTun(pointerOrDefaultTun(general.Tun, P.LastTunConf), tunnel.Tunnel)
|
||||
P.ReCreateShadowSocks(pointerOrDefaultString(general.ShadowSocksConfig, ports.ShadowSocksConfig), tunnel.Tunnel)
|
||||
P.ReCreateVmess(pointerOrDefaultString(general.VmessConfig, ports.VmessConfig), tunnel.Tunnel)
|
||||
P.ReCreateShadowSocks(pointerOrDefault(general.ShadowSocksConfig, ports.ShadowSocksConfig), tunnel.Tunnel)
|
||||
P.ReCreateVmess(pointerOrDefault(general.VmessConfig, ports.VmessConfig), tunnel.Tunnel)
|
||||
P.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, P.LastTuicConf), tunnel.Tunnel)
|
||||
|
||||
if general.Mode != nil {
|
||||
|
||||
Reference in New Issue
Block a user