From 0c995a247962e71514ebd8b88d388966ed6a5dfa Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sat, 17 Jan 2026 22:26:14 +0800 Subject: [PATCH] chore: move proxiesWithProviders to hub/route internal to disallow external usage of this poorly implemented function --- hub/route/proxies.go | 22 ++++++++++++++++++++-- tunnel/tunnel.go | 14 -------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/hub/route/proxies.go b/hub/route/proxies.go index f100adbb..bc7eed44 100644 --- a/hub/route/proxies.go +++ b/hub/route/proxies.go @@ -46,7 +46,7 @@ func parseProxyName(next http.Handler) http.Handler { func findProxyByName(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { name := r.Context().Value(CtxKeyProxyName).(string) - proxies := tunnel.ProxiesWithProviders() + proxies := proxiesWithProviders() proxy, exist := proxies[name] if !exist { render.Status(r, http.StatusNotFound) @@ -60,7 +60,7 @@ func findProxyByName(next http.Handler) http.Handler { } func getProxies(w http.ResponseWriter, r *http.Request) { - proxies := tunnel.ProxiesWithProviders() + proxies := proxiesWithProviders() render.JSON(w, r, render.M{ "proxies": proxies, }) @@ -158,3 +158,21 @@ func unfixedProxy(w http.ResponseWriter, r *http.Request) { render.Status(r, http.StatusBadRequest) render.JSON(w, r, ErrBadRequest) } + +// proxiesWithProviders merges all proxies from tunnel +// +// Deprecated: This function is poorly implemented and should not be called by any new code. +// It is left here only to ensure the compatibility of the output of the existing RESTful API. +func proxiesWithProviders() map[string]C.Proxy { + allProxies := make(map[string]C.Proxy) + for name, proxy := range tunnel.Proxies() { + allProxies[name] = proxy + } + for _, p := range tunnel.Providers() { + for _, proxy := range p.Proxies() { + name := proxy.Name() + allProxies[name] = proxy + } + } + return allProxies +} diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index dbd2bd53..fb2cc75b 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -208,20 +208,6 @@ func Proxies() map[string]C.Proxy { return proxies } -func ProxiesWithProviders() map[string]C.Proxy { - allProxies := make(map[string]C.Proxy) - for name, proxy := range proxies { - allProxies[name] = proxy - } - for _, p := range providers { - for _, proxy := range p.Proxies() { - name := proxy.Name() - allProxies[name] = proxy - } - } - return allProxies -} - // Providers return all compatible providers func Providers() map[string]P.ProxyProvider { return providers