9
9
"errors"
10
10
"fmt"
11
11
"io"
12
+ "net"
12
13
"net/http"
14
+ "strings"
13
15
"time"
14
16
15
17
"github.com/kataras/iris/v12/core/netutil"
@@ -26,9 +28,72 @@ func WriteStartupLogOnServe(w io.Writer) func(TaskHost) {
26
28
if addr == "" {
27
29
addr = h .Supervisor .Server .Addr
28
30
}
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.
29
73
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
+
30
80
_ , _ = fmt .Fprintf (w , "Now listening on: %s\n Application 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
+ */
32
97
}
33
98
}
34
99
0 commit comments