This commit is contained in:
Gerasimos (Makis) Maropoulos 2023-07-30 21:17:22 +03:00
parent d254d48f34
commit 353fd4dcba
No known key found for this signature in database
GPG Key ID: B9839E9CD30B7B6B
2 changed files with 67 additions and 2 deletions

View File

@ -9,7 +9,9 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"strings"
"time"
"github.com/kataras/iris/v12/core/netutil"
@ -26,9 +28,72 @@ func WriteStartupLogOnServe(w io.Writer) func(TaskHost) {
if addr == "" {
addr = h.Supervisor.Server.Addr
}
var listeningURIs = make([]string, 0, 1)
if host, port, err := net.SplitHostPort(addr); err == nil { // Improve for the issue #2175.
if host == "" || host == "0.0.0.0" {
if ifaces, err := net.Interfaces(); err == nil {
var ips []string
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
continue
}
for _, localAddr := range addrs {
var ip net.IP
switch v := localAddr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
if ip != nil && ip.To4() != nil {
if !ip.IsPrivate() {
// let's don't print ips that are not accessible through browser.
continue
}
ips = append(ips, ip.String())
}
}
}
for _, ip := range ips {
listeningURI := netutil.ResolveURL(guessScheme, fmt.Sprintf("%s:%s", ip, port))
listeningURI = "> Network: " + listeningURI
listeningURIs = append(listeningURIs, listeningURI)
}
}
}
}
// if len(listeningURIs) == 0 {
// ^ check no need, we want to print the virtual addr too.
listeningURI := netutil.ResolveURL(guessScheme, addr)
if len(listeningURIs) > 0 {
listeningURIs[0] = "\n" + listeningURIs[0]
listeningURI = "> Local: " + listeningURI
}
listeningURIs = append(listeningURIs, listeningURI)
_, _ = fmt.Fprintf(w, "Now listening on: %s\nApplication started. Press CTRL+C to shut down.\n",
listeningURI)
strings.Join(listeningURIs, "\n"))
/*
When :8080 or 0.0.0.0:8080:
Now listening on:
> Network: http://192.168.1.109:8080
> Network: http://172.25.224.1:8080
> Local: http://localhost:8080
Application started. Press CTRL+C to shut down.
Otherwise:
Iris Version: 12.2.1
Now listening on: http://192.168.1.109:8080
Application started. Press CTRL+C to shut down.
*/
}
}

View File

@ -38,7 +38,7 @@ import (
)
// Version is the current version of the Iris Web Framework.
const Version = "12.2.0"
const Version = "12.2.1"
// Byte unit helpers.
const (