diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-11-30 14:29:35 +0100 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-11-30 14:29:35 +0100 |
commit | b504ab8b02e2891c33e9883a4bb1a3e0f90b2b1e (patch) | |
tree | e3db46bf053d541724efe783c72a1cc780b056d4 /main.go | |
parent | 75416fe01aa98b53c57315a050fc58f0879a238d (diff) |
Add -u short option for --url and support port number only.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -143,7 +143,7 @@ func main() { Value: defaultLogLevel, }, cli.StringFlag{ - Name: "url", + Name: "url, u", EnvVar: "XDS_SERVER_URL", Value: "localhost:8000", Usage: "remote XDS server url", @@ -247,8 +247,15 @@ func XdsConnInit(ctx *cli.Context) error { // Define HTTP and WS url baseURL := ctx.String("url") - if !strings.HasPrefix(ctx.String("url"), "http://") { - baseURL = "http://" + ctx.String("url") + + // Allow to only set port number + if match, _ := regexp.MatchString("^([0-9]+)$", baseURL); match { + baseURL = "http://localhost:" + ctx.String("url") + } + + // Add http prefix if missing + if !strings.HasPrefix(baseURL, "http://") { + baseURL = "http://" + baseURL } // Create HTTP client |