Skip to content

Commit 353fd4d

Browse files
committed
implement #2175
1 parent d254d48 commit 353fd4d

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

core/host/task.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12+
"net"
1213
"net/http"
14+
"strings"
1315
"time"
1416

1517
"github.com/kataras/iris/v12/core/netutil"
@@ -26,9 +28,72 @@ func WriteStartupLogOnServe(w io.Writer) func(TaskHost) {
2628
if addr == "" {
2729
addr = h.Supervisor.Server.Addr
2830
}
31+
32+
var listeningURIs = make([]string, 0, 1)
33+
34+
if host, port, err := net.SplitHostPort(addr); err == nil { // Improve for the issue #2175.
35+
if host == "" || host == "0.0.0.0" {
36+
if ifaces, err := net.Interfaces(); err == nil {
37+
var ips []string
38+
for _, i := range ifaces {
39+
addrs, err := i.Addrs()
40+
if err != nil {
41+
continue
42+
}
43+
for _, localAddr := range addrs {
44+
var ip net.IP
45+
switch v := localAddr.(type) {
46+
case *net.IPNet:
47+
ip = v.IP
48+
case *net.IPAddr:
49+
ip = v.IP
50+
}
51+
if ip != nil && ip.To4() != nil {
52+
if !ip.IsPrivate() {
53+
// let's don't print ips that are not accessible through browser.
54+
continue
55+
}
56+
ips = append(ips, ip.String())
57+
}
58+
}
59+
}
60+
61+
for _, ip := range ips {
62+
listeningURI := netutil.ResolveURL(guessScheme, fmt.Sprintf("%s:%s", ip, port))
63+
64+
listeningURI = "> Network: " + listeningURI
65+
listeningURIs = append(listeningURIs, listeningURI)
66+
}
67+
}
68+
}
69+
}
70+
71+
// if len(listeningURIs) == 0 {
72+
// ^ check no need, we want to print the virtual addr too.
2973
listeningURI := netutil.ResolveURL(guessScheme, addr)
74+
if len(listeningURIs) > 0 {
75+
listeningURIs[0] = "\n" + listeningURIs[0]
76+
listeningURI = "> Local: " + listeningURI
77+
}
78+
listeningURIs = append(listeningURIs, listeningURI)
79+
3080
_, _ = fmt.Fprintf(w, "Now listening on: %s\nApplication started. Press CTRL+C to shut down.\n",
31-
listeningURI)
81+
strings.Join(listeningURIs, "\n"))
82+
83+
/*
84+
When :8080 or 0.0.0.0:8080:
85+
Now listening on:
86+
> Network: http://192.168.1.109:8080
87+
> Network: http://172.25.224.1:8080
88+
> Local: http://localhost:8080
89+
Application started. Press CTRL+C to shut down.
90+
91+
Otherwise:
92+
Iris Version: 12.2.1
93+
94+
Now listening on: http://192.168.1.109:8080
95+
Application started. Press CTRL+C to shut down.
96+
*/
3297
}
3398
}
3499

iris.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
)
3939

4040
// Version is the current version of the Iris Web Framework.
41-
const Version = "12.2.0"
41+
const Version = "12.2.1"
4242

4343
// Byte unit helpers.
4444
const (

0 commit comments

Comments
 (0)