first commit

This commit is contained in:
Adrian Zürcher
2026-01-16 07:51:28 +01:00
commit 4d9e0836e5
15 changed files with 764 additions and 0 deletions

51
handlers/infos.go Normal file
View File

@@ -0,0 +1,51 @@
package handlers
import (
"encoding/json"
"net"
"net/http"
"slideshowApp/env"
"strings"
)
// 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()
}
addrs, err := net.InterfaceAddrs()
if err != nil {
return "localhost"
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
if env.Env.GetValue() == "development" && !strings.Contains(ipnet.IP.String(), "192.168") {
continue
}
return ipnet.IP.String()
}
}
}
return "localhost"
}
func InfoHandler(w http.ResponseWriter, r *http.Request) {
port := env.Port.GetValue()
if port == "" {
port = "8080"
}
speed := env.IntervalDefault.GetValue()
if speed == "" {
speed = "10"
}
data := map[string]string{
"ip": getLocalIP(),
"port": port,
"speed": speed,
}
json.NewEncoder(w).Encode(data)
}