package handlers import ( "encoding/json" "net" "net/http" "slideshowApp/env" ) // Helper to get the local network IP address func GetLocalIP() string { if env.Host.GetValue() != "0.0.0.0" && env.Host.GetValue() != "localhost" { return env.Host.GetValue() } if ip := getActiveIP(); ip != "" { return ip } return "localhost" } func getActiveIP() string { conn, err := net.Dial("udp", "8.8.8.8:80") if err != nil { return "" } defer conn.Close() addr := conn.LocalAddr() if udpAddr, ok := addr.(*net.UDPAddr); ok { return udpAddr.IP.String() } return "" } func InfoHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") data := map[string]string{ "ip": GetLocalIP(), "port": env.Port.GetValue(), "speed": GetInterval(), } err := json.NewEncoder(w).Encode(data) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } }