Skip to content

Commit

Permalink
Fixed #42
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <vr@labstack.com>
  • Loading branch information
vishr committed May 1, 2018
1 parent 6c22892 commit 3336020
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IMAGE = labstack/armor
VERSION = 0.4.8
VERSION = 0.4.9

run:
go run cmd/armor/main.go
Expand Down
2 changes: 1 addition & 1 deletion armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type (
)

const (
Version = "0.4.8"
Version = "0.4.9"
Website = "https://armor.labstack.com"
)

Expand Down
9 changes: 8 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package armor

import (
"crypto/tls"
"fmt"
"net"
"net/http"
"path/filepath"
"time"
Expand Down Expand Up @@ -96,7 +98,12 @@ func (h *HTTP) Start() error {
a := h.armor
e := h.echo
if a.DefaultConfig {
a.Colorer.Printf("⇨ serving from %s\n", a.Colorer.Green("http://localhost"+a.Address))
a.Colorer.Printf("⇨ serving from %s (Local)\n", a.Colorer.Green("http://localhost"+a.Address))
ip := util.GetPrivateIP()
if ip != "" {
_, port, _ := net.SplitHostPort(a.Address)
a.Colorer.Printf("⇨ serving from %s (Intranet)\n", a.Colorer.Green(fmt.Sprintf("http://%s:%s", ip, port)))
}
} else {
a.Colorer.Printf("⇨ http server started on %s\n", a.Colorer.Green(a.Address))
}
Expand Down
16 changes: 16 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"net"
"strings"

"github.com/labstack/gommon/random"
Expand All @@ -22,3 +23,18 @@ func StripPort(host string) string {
}
return host[:colon]
}

func GetPrivateIP() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return ""
}
for _, address := range addrs {
if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
return ipNet.IP.String()
}
}
}
return ""
}
2 changes: 1 addition & 1 deletion website/content/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Type `armor` in your terminal
___
/ _ | ______ _ ___ ____
/ __ |/ __/ ' \/ _ \/ __/
/_/ |_/_/ /_/_/_/\___/_/ v0.4.8
/_/ |_/_/ /_/_/_/\___/_/ v0.4.9
Uncomplicated, modern HTTP server
https://armor.labstack.com
Expand Down

0 comments on commit 3336020

Please sign in to comment.