mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
implement #2175
This commit is contained in:
parent
d254d48f34
commit
353fd4dcba
|
@ -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.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user