From ab0b9b002f492530e3e9b2db99453731fcf72f56 Mon Sep 17 00:00:00 2001 From: kr-ilya Date: Sun, 4 Jan 2026 17:37:40 +0300 Subject: [PATCH] refactor: use any instead of empty interface --- main.go | 6 +++--- web/controller/server.go | 6 +++--- web/global/global.go | 2 +- web/job/xray_traffic_job.go | 2 +- web/service/server.go | 4 ++-- web/web.go | 2 +- web/websocket/hub.go | 6 +++--- web/websocket/notifier.go | 6 +++--- xray/api.go | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index e2af2beb..8096616c 100644 --- a/main.go +++ b/main.go @@ -80,8 +80,8 @@ func runWebServer() { // --- FIX FOR TELEGRAM BOT CONFLICT (409): Stop bot before restart --- service.StopBot() - // -- - + // -- + err := server.Stop() if err != nil { logger.Debug("Error stopping web server:", err) @@ -113,7 +113,7 @@ func runWebServer() { // --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown --- service.StopBot() // ------------------------------------------------------------ - + server.Stop() subServer.Stop() log.Println("Shutting down servers.") diff --git a/web/controller/server.go b/web/controller/server.go index 5b39700e..d32209e1 100644 --- a/web/controller/server.go +++ b/web/controller/server.go @@ -210,10 +210,10 @@ func (a *ServerController) getXrayLogs(c *gin.Context) { //getting tags for freedom and blackhole outbounds config, err := a.settingService.GetDefaultXrayConfig() if err == nil && config != nil { - if cfgMap, ok := config.(map[string]interface{}); ok { - if outbounds, ok := cfgMap["outbounds"].([]interface{}); ok { + if cfgMap, ok := config.(map[string]any); ok { + if outbounds, ok := cfgMap["outbounds"].([]any); ok { for _, outbound := range outbounds { - if obMap, ok := outbound.(map[string]interface{}); ok { + if obMap, ok := outbound.(map[string]any); ok { switch obMap["protocol"] { case "freedom": if tag, ok := obMap["tag"].(string); ok { diff --git a/web/global/global.go b/web/global/global.go index f72c7bfe..5556b486 100644 --- a/web/global/global.go +++ b/web/global/global.go @@ -17,7 +17,7 @@ var ( type WebServer interface { GetCron() *cron.Cron // Get the cron scheduler GetCtx() context.Context // Get the server context - GetWSHub() interface{} // Get the WebSocket hub (using interface{} to avoid circular dependency) + GetWSHub() any // Get the WebSocket hub (using any to avoid circular dependency) } // SubServer interface defines methods for accessing the subscription server instance. diff --git a/web/job/xray_traffic_job.go b/web/job/xray_traffic_job.go index 2f331cd6..62caddd4 100644 --- a/web/job/xray_traffic_job.go +++ b/web/job/xray_traffic_job.go @@ -59,7 +59,7 @@ func (j *XrayTrafficJob) Run() { } // Broadcast traffic update via WebSocket - trafficUpdate := map[string]interface{}{ + trafficUpdate := map[string]any{ "traffics": traffics, "clientTraffics": clientTraffics, "onlineClients": onlineClients, diff --git a/web/service/server.go b/web/service/server.go index 970c5c0f..49f13b91 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -1205,7 +1205,7 @@ func (s *ServerService) GetNewmldsa65() (any, error) { return keyPair, nil } -func (s *ServerService) GetNewEchCert(sni string) (interface{}, error) { +func (s *ServerService) GetNewEchCert(sni string) (any, error) { // Run the command cmd := exec.Command(xray.GetBinaryPath(), "tls", "ech", "--serverName", sni) var out bytes.Buffer @@ -1223,7 +1223,7 @@ func (s *ServerService) GetNewEchCert(sni string) (interface{}, error) { configList := lines[1] serverKeys := lines[3] - return map[string]interface{}{ + return map[string]any{ "echServerKeys": serverKeys, "echConfigList": configList, }, nil diff --git a/web/web.go b/web/web.go index 7dae08e3..300572a3 100644 --- a/web/web.go +++ b/web/web.go @@ -487,6 +487,6 @@ func (s *Server) GetCron() *cron.Cron { } // GetWSHub returns the WebSocket hub instance. -func (s *Server) GetWSHub() interface{} { +func (s *Server) GetWSHub() any { return s.wsHub } diff --git a/web/websocket/hub.go b/web/websocket/hub.go index 187ebb6f..181881e6 100644 --- a/web/websocket/hub.go +++ b/web/websocket/hub.go @@ -25,7 +25,7 @@ const ( // Message represents a WebSocket message type Message struct { Type MessageType `json:"type"` - Payload interface{} `json:"payload"` + Payload any `json:"payload"` Time int64 `json:"time"` } @@ -249,7 +249,7 @@ func (h *Hub) broadcastParallel(clients []*Client, message []byte) { } // Broadcast sends a message to all connected clients -func (h *Hub) Broadcast(messageType MessageType, payload interface{}) { +func (h *Hub) Broadcast(messageType MessageType, payload any) { if h == nil { return } @@ -288,7 +288,7 @@ func (h *Hub) Broadcast(messageType MessageType, payload interface{}) { } // BroadcastToTopic sends a message only to clients subscribed to the specific topic -func (h *Hub) BroadcastToTopic(messageType MessageType, payload interface{}) { +func (h *Hub) BroadcastToTopic(messageType MessageType, payload any) { if h == nil { return } diff --git a/web/websocket/notifier.go b/web/websocket/notifier.go index cedf56f2..5a6c2eb1 100644 --- a/web/websocket/notifier.go +++ b/web/websocket/notifier.go @@ -25,7 +25,7 @@ func GetHub() *Hub { } // BroadcastStatus broadcasts server status update to all connected clients -func BroadcastStatus(status interface{}) { +func BroadcastStatus(status any) { hub := GetHub() if hub != nil { hub.Broadcast(MessageTypeStatus, status) @@ -33,7 +33,7 @@ func BroadcastStatus(status interface{}) { } // BroadcastTraffic broadcasts traffic statistics update to all connected clients -func BroadcastTraffic(traffic interface{}) { +func BroadcastTraffic(traffic any) { hub := GetHub() if hub != nil { hub.Broadcast(MessageTypeTraffic, traffic) @@ -41,7 +41,7 @@ func BroadcastTraffic(traffic interface{}) { } // BroadcastInbounds broadcasts inbounds list update to all connected clients -func BroadcastInbounds(inbounds interface{}) { +func BroadcastInbounds(inbounds any) { hub := GetHub() if hub != nil { hub.Broadcast(MessageTypeInbounds, inbounds) diff --git a/xray/api.go b/xray/api.go index 95d8c473..2312d2e4 100644 --- a/xray/api.go +++ b/xray/api.go @@ -116,7 +116,7 @@ func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]an } // Add testseed if provided if testseedVal, ok := user["testseed"]; ok { - if testseedArr, ok := testseedVal.([]interface{}); ok && len(testseedArr) >= 4 { + if testseedArr, ok := testseedVal.([]any); ok && len(testseedArr) >= 4 { testseed := make([]uint32, len(testseedArr)) for i, v := range testseedArr { if num, ok := v.(float64); ok {