Skip to content

Commit

Permalink
main.go: use flagx.Enum for the -scheme flag
Browse files Browse the repository at this point in the history
Allows to narrow down the allowed values to ws and wss
as suggested by @pboothe during the review.
  • Loading branch information
bassosimone committed Dec 12, 2019
1 parent 91b9568 commit 0ef9a31
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/ndt7-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import (
"os"
"time"

"github.com/m-lab/go/flagx"
"github.com/m-lab/ndt7-client-go"
"github.com/m-lab/ndt7-client-go/cmd/ndt7-client/internal/emitter"
"github.com/m-lab/ndt7-client-go/spec"
Expand All @@ -92,15 +93,25 @@ const (
)

var (
flagScheme = flagx.Enum{
Options: []string{"wss", "ws"},
Value: "wss",
}
flagBatch = flag.Bool("batch", false, "emit JSON events on stdout")
flagNoVerify = flag.Bool("no-verify", false, "skip TLS certificate verification")
flagHostname = flag.String("hostname", "", "optional ndt7 server hostname")
flagScheme = flag.String(
"scheme", "wss", `use "wss" for encrypted ndt7, "ws" for cleartext ndt7`)
flagTimeout = flag.Duration(
flagTimeout = flag.Duration(
"timeout", defaultTimeout, "time after which the test is aborted")
)

func init() {
flag.Var(
&flagScheme,
"scheme",
`WebSocket scheme to use: either "wss" (the default) or "ws"`,
)
}

type runner struct {
client *ndt7.Client
emitter emitter.Emitter
Expand Down Expand Up @@ -167,7 +178,7 @@ func main() {
defer cancel()
var r runner
r.client = ndt7.NewClient(clientName, clientVersion)
r.client.Scheme = *flagScheme
r.client.Scheme = flagScheme.Value
r.client.Dialer.TLSClientConfig = &tls.Config{
InsecureSkipVerify: *flagNoVerify,
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.12

require (
github.com/gorilla/websocket v1.4.1
github.com/m-lab/go v1.2.0
github.com/m-lab/ndt-server v0.13.4
github.com/m-lab/tcp-info v1.3.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/m-lab/go v1.2.0 h1:tIYz23bGCuw1AH7wl5h+vAJ5VV1aXgo9Zbl+Evkdp/o=
github.com/m-lab/go v1.2.0/go.mod h1:FcVx/N8dL5J5TVQ2L0d8/cAw/ljR6fhwZqvqZHrb5/Q=
github.com/m-lab/ndt-server v0.13.4 h1:0rjWbZsor6/CRxOMlWxWEq1I7GUWrNCTM6//OFNC3Yo=
github.com/m-lab/ndt-server v0.13.4/go.mod h1:ZLVRCEbCBkhh0pwNjnLpwaZnHOHGEH76H/fzIIVFRWw=
github.com/m-lab/tcp-info v1.3.0 h1:bL8ElOp5Sxc5e1W86swMv5zjh6/y1Y9qT7eEOgJnzq4=
Expand Down

0 comments on commit 0ef9a31

Please sign in to comment.