From ea1c43eb259aeefa340bdf99339f4e76bc744e4f Mon Sep 17 00:00:00 2001 From: Randall Meyer Date: Fri, 10 Feb 2023 14:37:56 -0800 Subject: new flag: --url This enables passing in a single URL for easier running eg networkQuality --url https://networkquality.example.com/path/to/config --- networkQuality.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'networkQuality.go') diff --git a/networkQuality.go b/networkQuality.go index 1af90bb..12aa724 100644 --- a/networkQuality.go +++ b/networkQuality.go @@ -18,6 +18,7 @@ import ( "context" "flag" "fmt" + "net/url" "os" "runtime/pprof" "time" @@ -53,6 +54,11 @@ var ( "config", "path on the server to the configuration endpoint.", ) + configURL = flag.String( + "url", + "", + "configuration URL (takes precedence over other configuration parts)", + ) debugCliFlag = flag.Bool( "debug", constants.DefaultDebug, @@ -95,7 +101,24 @@ func main() { timeoutDuration := time.Second * time.Duration(*rpmtimeout) timeoutAbsoluteTime := time.Now().Add(timeoutDuration) - configHostPort := fmt.Sprintf("%s:%d", *configHost, *configPort) + + var configHostPort string + + // if user specified a full URL, use that and set the various parts we need out of it + if len(*configURL) > 0 { + parsedURL, err := url.ParseRequestURI(*configURL) + if err != nil { + fmt.Printf("Error: Could not parse %q: %s", *configURL, err) + os.Exit(1) + } + + *configHost = parsedURL.Hostname() + *configPath = parsedURL.Path + // We don't explicitly care about configuring the *configPort. + configHostPort = parsedURL.Host // host or host:port + } else { + configHostPort = fmt.Sprintf("%s:%d", *configHost, *configPort) + } // This is the overall operating context of the program. All other // contexts descend from this one. Canceling this one cancels all -- cgit v1.2.3