config: Accept more address format + unit test (#3915)

checkURL() is a generic function to check if a passed address
is valid. This commit adds support for addresses like `m1`
and `172.16.3.1` which is needed in MySQL and NATS. This commit
also adds tests.
This commit is contained in:
Anis Elleuch
2017-03-16 19:44:01 +01:00
committed by Harshavardhana
parent f3334159a4
commit 8426cf9aec
8 changed files with 39 additions and 12 deletions

View File

@@ -19,6 +19,7 @@ package cmd
import (
"encoding/base64"
"encoding/xml"
"errors"
"fmt"
"io"
"net/http"
@@ -263,15 +264,14 @@ func isFile(path string) bool {
return false
}
// checkNetURL - checks if passed address correspond
// to a network address (and not file system path)
func checkNetURL(address string) (*url.URL, error) {
// checkURL - checks if passed address correspond
func checkURL(address string) (*url.URL, error) {
if address == "" {
return nil, errors.New("Address cannot be empty")
}
u, err := url.Parse(address)
if err != nil {
return nil, fmt.Errorf("`%s` invalid: %s", address, err.Error())
}
if u.Host == "" {
return nil, fmt.Errorf("`%s` invalid network URL", address)
}
return u, nil
}