Make env var parsing more robust

pull/578/head
jackgr 9 years ago
parent 624dad3ef7
commit b5871d7a53

@ -20,6 +20,7 @@ import (
"fmt"
"log"
"net"
"net/url"
"os"
"strings"
)
@ -77,7 +78,13 @@ func GetServiceURL(serviceName, servicePort, serviceURL string) (string, error)
varName := strings.ToUpper(varBase) + "_PORT"
serviceURL := os.Getenv(varName)
if serviceURL != "" {
return strings.Replace(serviceURL, "tcp", "http", 1), nil
u, err := url.Parse(serviceURL)
if err != nil || u.Path != "" || u.Scheme != "tcp" {
return "", fmt.Errorf("malformed value: %s for envinronment variable: %s", serviceURL, varName)
}
u.Scheme = "http"
return u.String(), nil
}
if servicePort != "" {

Loading…
Cancel
Save