Embedded NATS Broker (#1110)

* if the address is produced by a default route don't hash it

* embedded nats

* fix url parsing

* don't override help

* add ready flag
This commit is contained in:
Asim Aslam
2020-01-14 13:23:16 +00:00
committed by GitHub
parent b699d969e4
commit 1d311ab457
10 changed files with 308 additions and 41 deletions

View File

@@ -27,6 +27,29 @@ func isPrivateIP(ipAddr string) bool {
return false
}
// IsLocal tells us whether an ip is local
func IsLocal(addr string) bool {
// extract the host
host, _, err := net.SplitHostPort(addr)
if err == nil {
addr = host
}
// check if its localhost
if addr == "localhost" {
return true
}
// check against all local ips
for _, ip := range IPs() {
if addr == ip {
return true
}
}
return false
}
// Extract returns a real ip
func Extract(addr string) (string, error) {
// if addr specified then its returned

View File

@@ -5,6 +5,26 @@ import (
"testing"
)
func TestIsLocal(t *testing.T) {
testData := []struct {
addr string
expect bool
}{
{"localhost", true},
{"localhost:8080", true},
{"127.0.0.1", true},
{"127.0.0.1:1001", true},
{"80.1.1.1", false},
}
for _, d := range testData {
res := IsLocal(d.addr)
if res != d.expect {
t.Fatalf("expected %t got %t", d.expect, res)
}
}
}
func TestExtractor(t *testing.T) {
testData := []struct {
addr string