Commit b5871d7a authored by jackgr's avatar jackgr

Make env var parsing more robust

parent 624dad3e
......@@ -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 != "" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment