fix: useful Docker bind address output in serve

When binding to 0.0.0.0 (--host 0.0.0.0), print "localhost" and
"<host-ip>" URLs instead of the raw 0.0.0.0 address. Also handles
nil TCPAddr.IP to avoid the ":::" garbled display in Docker.
This commit is contained in:
2026-06-21 22:00:27 -07:00
parent ca0cd10436
commit 4c09fb8d9b
2 changed files with 14 additions and 8 deletions
+13 -3
View File
@@ -65,12 +65,22 @@ func cmdServe(args []string) {
}
realPort := listener.Addr().(*net.TCPAddr).Port
realHost := listener.Addr().(*net.TCPAddr).IP.String()
realHost := "0.0.0.0"
if ip := listener.Addr().(*net.TCPAddr).IP; ip != nil {
realHost = ip.String()
}
fmt.Printf("\n AKAI Utils Server\n")
fmt.Printf(" =================\n\n")
fmt.Printf(" Local: http://%s:%d\n", realHost, realPort)
fmt.Printf(" API: http://%s:%d/api/\n", realHost, realPort)
if realHost == "0.0.0.0" || realHost == "::" || realHost == "" || realHost == "<nil>" {
fmt.Printf(" Local: http://localhost:%d\n", realPort)
if realHost == "0.0.0.0" {
fmt.Printf(" Network: http://<host-ip>:%d\n", realPort)
}
} else {
fmt.Printf(" Local: http://%s:%d\n", realHost, realPort)
}
fmt.Printf(" API: http://localhost:%d/api/\n", realPort)
fmt.Printf(" Quit: Ctrl+C\n\n")
if openBrowser {