Add validation for Endpoints

This commit is contained in:
gmarek
2015-03-20 15:40:20 +01:00
parent e44ec497ed
commit c20efb6bae
4 changed files with 218 additions and 11 deletions

View File

@@ -91,7 +91,7 @@ func IsValidPortNum(port int) bool {
return 0 < port && port < 65536
}
// IsValidIP tests that the argument is a valid IPv4 address.
func IsValidIP(value string) bool {
// IsValidIPv4 tests that the argument is a valid IPv4 address.
func IsValidIPv4(value string) bool {
return net.ParseIP(value) != nil && net.ParseIP(value).To4() != nil
}

View File

@@ -232,7 +232,7 @@ func TestIsValidIP(t *testing.T) {
"0.0.0.0",
}
for _, val := range goodValues {
if !IsValidIP(val) {
if !IsValidIPv4(val) {
t.Errorf("expected true for %q", val)
}
}
@@ -247,7 +247,7 @@ func TestIsValidIP(t *testing.T) {
"1.0.0.1.",
}
for _, val := range badValues {
if IsValidIP(val) {
if IsValidIPv4(val) {
t.Errorf("expected false for %q", val)
}
}