refactor: use any instead of empty interface

This commit is contained in:
kr-ilya 2026-01-04 17:37:40 +03:00
parent 3f15d21f13
commit ab0b9b002f
9 changed files with 18 additions and 18 deletions

View file

@ -80,8 +80,8 @@ func runWebServer() {
// --- FIX FOR TELEGRAM BOT CONFLICT (409): Stop bot before restart --- // --- FIX FOR TELEGRAM BOT CONFLICT (409): Stop bot before restart ---
service.StopBot() service.StopBot()
// -- // --
err := server.Stop() err := server.Stop()
if err != nil { if err != nil {
logger.Debug("Error stopping web server:", err) logger.Debug("Error stopping web server:", err)
@ -113,7 +113,7 @@ func runWebServer() {
// --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown --- // --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown ---
service.StopBot() service.StopBot()
// ------------------------------------------------------------ // ------------------------------------------------------------
server.Stop() server.Stop()
subServer.Stop() subServer.Stop()
log.Println("Shutting down servers.") log.Println("Shutting down servers.")

View file

@ -210,10 +210,10 @@ func (a *ServerController) getXrayLogs(c *gin.Context) {
//getting tags for freedom and blackhole outbounds //getting tags for freedom and blackhole outbounds
config, err := a.settingService.GetDefaultXrayConfig() config, err := a.settingService.GetDefaultXrayConfig()
if err == nil && config != nil { if err == nil && config != nil {
if cfgMap, ok := config.(map[string]interface{}); ok { if cfgMap, ok := config.(map[string]any); ok {
if outbounds, ok := cfgMap["outbounds"].([]interface{}); ok { if outbounds, ok := cfgMap["outbounds"].([]any); ok {
for _, outbound := range outbounds { for _, outbound := range outbounds {
if obMap, ok := outbound.(map[string]interface{}); ok { if obMap, ok := outbound.(map[string]any); ok {
switch obMap["protocol"] { switch obMap["protocol"] {
case "freedom": case "freedom":
if tag, ok := obMap["tag"].(string); ok { if tag, ok := obMap["tag"].(string); ok {

View file

@ -17,7 +17,7 @@ var (
type WebServer interface { type WebServer interface {
GetCron() *cron.Cron // Get the cron scheduler GetCron() *cron.Cron // Get the cron scheduler
GetCtx() context.Context // Get the server context 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. // SubServer interface defines methods for accessing the subscription server instance.

View file

@ -59,7 +59,7 @@ func (j *XrayTrafficJob) Run() {
} }
// Broadcast traffic update via WebSocket // Broadcast traffic update via WebSocket
trafficUpdate := map[string]interface{}{ trafficUpdate := map[string]any{
"traffics": traffics, "traffics": traffics,
"clientTraffics": clientTraffics, "clientTraffics": clientTraffics,
"onlineClients": onlineClients, "onlineClients": onlineClients,

View file

@ -1205,7 +1205,7 @@ func (s *ServerService) GetNewmldsa65() (any, error) {
return keyPair, nil return keyPair, nil
} }
func (s *ServerService) GetNewEchCert(sni string) (interface{}, error) { func (s *ServerService) GetNewEchCert(sni string) (any, error) {
// Run the command // Run the command
cmd := exec.Command(xray.GetBinaryPath(), "tls", "ech", "--serverName", sni) cmd := exec.Command(xray.GetBinaryPath(), "tls", "ech", "--serverName", sni)
var out bytes.Buffer var out bytes.Buffer
@ -1223,7 +1223,7 @@ func (s *ServerService) GetNewEchCert(sni string) (interface{}, error) {
configList := lines[1] configList := lines[1]
serverKeys := lines[3] serverKeys := lines[3]
return map[string]interface{}{ return map[string]any{
"echServerKeys": serverKeys, "echServerKeys": serverKeys,
"echConfigList": configList, "echConfigList": configList,
}, nil }, nil

View file

@ -487,6 +487,6 @@ func (s *Server) GetCron() *cron.Cron {
} }
// GetWSHub returns the WebSocket hub instance. // GetWSHub returns the WebSocket hub instance.
func (s *Server) GetWSHub() interface{} { func (s *Server) GetWSHub() any {
return s.wsHub return s.wsHub
} }

View file

@ -25,7 +25,7 @@ const (
// Message represents a WebSocket message // Message represents a WebSocket message
type Message struct { type Message struct {
Type MessageType `json:"type"` Type MessageType `json:"type"`
Payload interface{} `json:"payload"` Payload any `json:"payload"`
Time int64 `json:"time"` Time int64 `json:"time"`
} }
@ -249,7 +249,7 @@ func (h *Hub) broadcastParallel(clients []*Client, message []byte) {
} }
// Broadcast sends a message to all connected clients // 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 { if h == nil {
return 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 // 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 { if h == nil {
return return
} }

View file

@ -25,7 +25,7 @@ func GetHub() *Hub {
} }
// BroadcastStatus broadcasts server status update to all connected clients // BroadcastStatus broadcasts server status update to all connected clients
func BroadcastStatus(status interface{}) { func BroadcastStatus(status any) {
hub := GetHub() hub := GetHub()
if hub != nil { if hub != nil {
hub.Broadcast(MessageTypeStatus, status) hub.Broadcast(MessageTypeStatus, status)
@ -33,7 +33,7 @@ func BroadcastStatus(status interface{}) {
} }
// BroadcastTraffic broadcasts traffic statistics update to all connected clients // BroadcastTraffic broadcasts traffic statistics update to all connected clients
func BroadcastTraffic(traffic interface{}) { func BroadcastTraffic(traffic any) {
hub := GetHub() hub := GetHub()
if hub != nil { if hub != nil {
hub.Broadcast(MessageTypeTraffic, traffic) hub.Broadcast(MessageTypeTraffic, traffic)
@ -41,7 +41,7 @@ func BroadcastTraffic(traffic interface{}) {
} }
// BroadcastInbounds broadcasts inbounds list update to all connected clients // BroadcastInbounds broadcasts inbounds list update to all connected clients
func BroadcastInbounds(inbounds interface{}) { func BroadcastInbounds(inbounds any) {
hub := GetHub() hub := GetHub()
if hub != nil { if hub != nil {
hub.Broadcast(MessageTypeInbounds, inbounds) hub.Broadcast(MessageTypeInbounds, inbounds)

View file

@ -116,7 +116,7 @@ func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]an
} }
// Add testseed if provided // Add testseed if provided
if testseedVal, ok := user["testseed"]; ok { 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)) testseed := make([]uint32, len(testseedArr))
for i, v := range testseedArr { for i, v := range testseedArr {
if num, ok := v.(float64); ok { if num, ok := v.(float64); ok {