-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathargs.go
72 lines (64 loc) · 2.86 KB
/
args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"os"
"github.com/kffl/gocannon/common"
"gopkg.in/alecthomas/kingpin.v2"
)
func parseRequestBody(s kingpin.Settings) *common.RawRequestBody {
r := &common.RawRequestBody{}
s.SetValue((*common.RawRequestBody)(r))
return r
}
func parseRequestHeaders(s kingpin.Settings) *common.RequestHeaders {
r := &common.RequestHeaders{}
s.SetValue((*common.RequestHeaders)(r))
return r
}
func parseArgs() (common.Config, error) {
var app = kingpin.New("gocannon", "Performance-focused HTTP load testing tool.")
var config = common.Config{
Duration: app.Flag("duration", "Load test duration.").
Short('d').
Default("10s").
Duration(),
Connections: app.Flag("connections", "Maximum number of concurrent connections.").
Short('c').
Default("50").
Int(),
Timeout: app.Flag("timeout", "HTTP client timeout.").
Short('t').
Default("200ms").
Duration(),
Mode: app.Flag("mode", "Statistics collection mode: reqlog (logs each request) or hist (stores histogram of completed requests latencies).").
Default("reqlog").
Short('m').
String(),
OutputFile: app.Flag("output", "File to save the request log in CSV format (reqlog mode) or a text file with raw histogram data (hist mode).").
PlaceHolder("file.csv").
Short('o').
String(),
CPUs: app.Flag("cpus", "Maximum number of logical CPUs that can be utilised. Defaults to the number of available CPU threads (or the GOMAXPROCS env variable).").
Default("0").
Int(),
Interval: app.Flag("interval", "Interval for statistics calculation (reqlog mode).").
Default("250ms").
Short('i').
Duration(),
Preallocate: app.Flag("preallocate", "Number of requests in req log to preallocate memory for per connection (reqlog mode).").
Default("1000").
Int(),
Method: app.Flag("method", "The HTTP request method (GET, POST, PUT, PATCH or DELETE).").Default("GET").Enum("GET", "POST", "PUT", "PATCH", "DELETE"),
Body: parseRequestBody(app.Flag("body", "HTTP request body.").Short('b').PlaceHolder("\"{data...\"")),
Headers: parseRequestHeaders(app.Flag("header", "HTTP request header(s). You can set more than one header by repeating this flag.").Short('h').PlaceHolder("\"k:v\"")),
TrustAll: app.Flag("trust-all", "Omit SSL certificate validation.").Bool(),
Format: app.Flag("format", "Load test report format. Either 'default' (verbose), 'json' or 'yaml'. When json or yaml is specified, apart from the load test results, no additional info will be written to std out.").
Short('f').
Default("default").
Enum("default", "json", "yaml"),
Plugin: app.Flag("plugin", "Plugin to run Gocannon with (path to .so file).").PlaceHolder("/to/p.so").ExistingFile(),
Target: app.Arg("target", "HTTP target URL with port (i.e. http://localhost:80/test or https://host:443/x)").Required().String(),
}
app.Version("1.3.0")
_, err := app.Parse(os.Args[1:])
return config, err
}