Skip to content

Commit

Permalink
implement #2175
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Jul 30, 2023
1 parent d254d48 commit 353fd4d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
67 changes: 66 additions & 1 deletion core/host/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"strings"
"time"

"github.com/kataras/iris/v12/core/netutil"
Expand All @@ -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.
*/
}
}

Expand Down
2 changes: 1 addition & 1 deletion iris.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 353fd4d

Please sign in to comment.