Skip to content

Commit 3336020

Browse files
committed
Fixed #42
Signed-off-by: Vishal Rana <[email protected]>
1 parent 6c22892 commit 3336020

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGE = labstack/armor
2-
VERSION = 0.4.8
2+
VERSION = 0.4.9
33

44
run:
55
go run cmd/armor/main.go

armor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type (
9292
)
9393

9494
const (
95-
Version = "0.4.8"
95+
Version = "0.4.9"
9696
Website = "https://armor.labstack.com"
9797
)
9898

http.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package armor
22

33
import (
44
"crypto/tls"
5+
"fmt"
6+
"net"
57
"net/http"
68
"path/filepath"
79
"time"
@@ -96,7 +98,12 @@ func (h *HTTP) Start() error {
9698
a := h.armor
9799
e := h.echo
98100
if a.DefaultConfig {
99-
a.Colorer.Printf("⇨ serving from %s\n", a.Colorer.Green("http://localhost"+a.Address))
101+
a.Colorer.Printf("⇨ serving from %s (Local)\n", a.Colorer.Green("http://localhost"+a.Address))
102+
ip := util.GetPrivateIP()
103+
if ip != "" {
104+
_, port, _ := net.SplitHostPort(a.Address)
105+
a.Colorer.Printf("⇨ serving from %s (Intranet)\n", a.Colorer.Green(fmt.Sprintf("http://%s:%s", ip, port)))
106+
}
100107
} else {
101108
a.Colorer.Printf("⇨ http server started on %s\n", a.Colorer.Green(a.Address))
102109
}

util/util.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package util
22

33
import (
4+
"net"
45
"strings"
56

67
"github.com/labstack/gommon/random"
@@ -22,3 +23,18 @@ func StripPort(host string) string {
2223
}
2324
return host[:colon]
2425
}
26+
27+
func GetPrivateIP() string {
28+
addrs, err := net.InterfaceAddrs()
29+
if err != nil {
30+
return ""
31+
}
32+
for _, address := range addrs {
33+
if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
34+
if ipNet.IP.To4() != nil {
35+
return ipNet.IP.String()
36+
}
37+
}
38+
}
39+
return ""
40+
}

website/content/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Type `armor` in your terminal
4444
___
4545
/ _ | ______ _ ___ ____
4646
/ __ |/ __/ ' \/ _ \/ __/
47-
/_/ |_/_/ /_/_/_/\___/_/ v0.4.8
47+
/_/ |_/_/ /_/_/_/\___/_/ v0.4.9
4848
4949
Uncomplicated, modern HTTP server
5050
https://armor.labstack.com

0 commit comments

Comments
 (0)