From ff76576cbea27a883d20acc796d806694c57e3fc Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Thu, 6 Nov 2025 19:39:03 +0800 Subject: [PATCH] chore: cleanup import path for listener --- config/config.go | 15 ++++++++------- hub/route/configs.go | 26 +++++++++++++------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/config/config.go b/config/config.go index f323631f..efc89032 100644 --- a/config/config.go +++ b/config/config.go @@ -28,7 +28,7 @@ import ( P "github.com/metacubex/mihomo/constant/provider" snifferTypes "github.com/metacubex/mihomo/constant/sniffer" "github.com/metacubex/mihomo/dns" - L "github.com/metacubex/mihomo/listener" + "github.com/metacubex/mihomo/listener" LC "github.com/metacubex/mihomo/listener/config" "github.com/metacubex/mihomo/log" R "github.com/metacubex/mihomo/rules" @@ -653,11 +653,11 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) { config.Proxies = proxies config.Providers = providers - listener, err := parseListeners(rawCfg) + listeners, err := parseListeners(rawCfg) if err != nil { return nil, err } - config.Listeners = listener + config.Listeners = listeners log.Infoln("Geodata Loader mode: %s", geodata.LoaderName()) log.Infoln("Geosite Matcher implementation: %s", geodata.SiteMatcherName()) @@ -957,16 +957,17 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[ func parseListeners(cfg *RawConfig) (listeners map[string]C.InboundListener, err error) { listeners = make(map[string]C.InboundListener) for index, mapping := range cfg.Listeners { - listener, err := L.ParseListener(mapping) + inboundListener, err := listener.ParseListener(mapping) if err != nil { return nil, fmt.Errorf("proxy %d: %w", index, err) } - if _, exist := mapping[listener.Name()]; exist { - return nil, fmt.Errorf("listener %s is the duplicate name", listener.Name()) + name := inboundListener.Name() + if _, exist := mapping[name]; exist { + return nil, fmt.Errorf("listener %s is the duplicate name", name) } - listeners[listener.Name()] = listener + listeners[name] = inboundListener } return diff --git a/hub/route/configs.go b/hub/route/configs.go index 92253c3f..141a6c15 100644 --- a/hub/route/configs.go +++ b/hub/route/configs.go @@ -13,7 +13,7 @@ import ( "github.com/metacubex/mihomo/config" C "github.com/metacubex/mihomo/constant" "github.com/metacubex/mihomo/hub/executor" - P "github.com/metacubex/mihomo/listener" + "github.com/metacubex/mihomo/listener" LC "github.com/metacubex/mihomo/listener/config" "github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/tunnel" @@ -306,7 +306,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) { } if general.AllowLan != nil { - P.SetAllowLan(*general.AllowLan) + listener.SetAllowLan(*general.AllowLan) } if general.SkipAuthPrefixes != nil { @@ -322,7 +322,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) { } if general.BindAddress != nil { - P.SetBindAddress(*general.BindAddress) + listener.SetBindAddress(*general.BindAddress) } if general.Sniffing != nil { @@ -337,17 +337,17 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) { dialer.DefaultInterface.Store(*general.InterfaceName) } - ports := P.GetPorts() + ports := listener.GetPorts() - P.ReCreateHTTP(pointerOrDefault(general.Port, ports.Port), tunnel.Tunnel) - P.ReCreateSocks(pointerOrDefault(general.SocksPort, ports.SocksPort), tunnel.Tunnel) - P.ReCreateRedir(pointerOrDefault(general.RedirPort, ports.RedirPort), tunnel.Tunnel) - 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(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) + listener.ReCreateHTTP(pointerOrDefault(general.Port, ports.Port), tunnel.Tunnel) + listener.ReCreateSocks(pointerOrDefault(general.SocksPort, ports.SocksPort), tunnel.Tunnel) + listener.ReCreateRedir(pointerOrDefault(general.RedirPort, ports.RedirPort), tunnel.Tunnel) + listener.ReCreateTProxy(pointerOrDefault(general.TProxyPort, ports.TProxyPort), tunnel.Tunnel) + listener.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tunnel.Tunnel) + listener.ReCreateTun(pointerOrDefaultTun(general.Tun, listener.LastTunConf), tunnel.Tunnel) + listener.ReCreateShadowSocks(pointerOrDefault(general.ShadowSocksConfig, ports.ShadowSocksConfig), tunnel.Tunnel) + listener.ReCreateVmess(pointerOrDefault(general.VmessConfig, ports.VmessConfig), tunnel.Tunnel) + listener.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, listener.LastTuicConf), tunnel.Tunnel) if general.Mode != nil { tunnel.SetMode(*general.Mode)