summaryrefslogtreecommitdiff
path: root/networkQuality.go
diff options
context:
space:
mode:
authorRandall Meyer <[email protected]>2023-02-10 14:37:56 -0800
committerRandall Meyer <[email protected]>2023-02-20 10:28:21 -0800
commitea1c43eb259aeefa340bdf99339f4e76bc744e4f (patch)
treeff9dc7591b4c30d31e4aa205b6f0b735c8d70f88 /networkQuality.go
parent0c2391d9db9ca1e199050ba91ef8d5cf508b9b95 (diff)
new flag: --url
This enables passing in a single URL for easier running eg networkQuality --url https://networkquality.example.com/path/to/config
Diffstat (limited to 'networkQuality.go')
-rw-r--r--networkQuality.go25
1 files changed, 24 insertions, 1 deletions
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