Skip to content

Commit f33c5c9

Browse files
committed
Unspecified time unit defaults to second.
1 parent d0b8659 commit f33c5c9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

goben/main.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strconv"
99
"strings"
1010
"time"
11+
"unicode"
1112
)
1213

1314
const version = "0.0"
@@ -53,15 +54,18 @@ func main() {
5354
flag.Var(&app.listeners, "listeners", "comma-separated list of listen addresses\nyou may prepend an optional host to every port: [host]:port")
5455
flag.StringVar(&app.defaultPort, "defaultPort", ":8080", "default port")
5556
flag.IntVar(&app.connections, "connections", 1, "number of parallel connections")
56-
flag.StringVar(&app.reportInterval, "reportInterval", "2s", "periodic report interval")
57-
flag.StringVar(&app.totalDuration, "totalDuration", "10s", "test total duration")
57+
flag.StringVar(&app.reportInterval, "reportInterval", "2s", "periodic report interval\nunspecified time unit defaults to second")
58+
flag.StringVar(&app.totalDuration, "totalDuration", "10s", "test total duration\nunspecified time unit defaults to second")
5859
flag.IntVar(&app.opt.ReadSize, "readSize", 20000, "read buffer size in bytes")
5960
flag.IntVar(&app.opt.WriteSize, "writeSize", 20000, "write buffer size in bytes")
6061
flag.BoolVar(&app.passiveClient, "passiveClient", false, "suppress client writes")
6162
flag.BoolVar(&app.opt.PassiveServer, "passiveServer", false, "suppress server writes")
6263

6364
flag.Parse()
6465

66+
app.reportInterval = defaultTimeUnit(app.reportInterval)
67+
app.totalDuration = defaultTimeUnit(app.totalDuration)
68+
6569
var errInterval error
6670
app.opt.ReportInterval, errInterval = time.ParseDuration(app.reportInterval)
6771
if errInterval != nil {
@@ -92,3 +96,14 @@ func main() {
9296
log.Printf("client mode")
9397
open(&app)
9498
}
99+
100+
// append "s" (second) to time string
101+
func defaultTimeUnit(s string) string {
102+
if len(s) < 1 {
103+
return s
104+
}
105+
if unicode.IsDigit(rune(s[len(s)-1])) {
106+
return s + "s"
107+
}
108+
return s
109+
}

0 commit comments

Comments
 (0)