-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (89 loc) · 1.94 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"os"
"regexp"
"github.com/hmarf/trunks/benche"
"github.com/hmarf/trunks/benche/attack"
"github.com/urfave/cli"
)
func headerSplit(header string) []string {
re := regexp.MustCompile(`^([\w-]+):\s*(.+)`)
return re.FindStringSubmatch(header)
}
func App() *cli.App {
app := cli.NewApp()
app.Name = "trunks"
app.Usage = "Trunks is a simple command line tool for HTTP load testing."
app.Version = "0.1.2"
app.Author = "hmarf"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "url, u",
Value: "None",
Usage: "[required] string\n URL to hit",
},
cli.IntFlag{
Name: "concurrency, c",
Value: 10,
Usage: "int\n Concurrency Level.",
},
cli.IntFlag{
Name: "requests, r",
Value: 100,
Usage: "int\n Number of Requests.",
},
cli.StringFlag{
Name: "method, m",
Value: "GET",
Usage: "string\n http method.",
},
cli.StringSliceFlag{
Name: "header, H",
Usage: "string\n HTTP header",
},
cli.StringFlag{
Name: "body, b",
Usage: "string\n HTTP body",
},
cli.StringFlag{
Name: "output, o",
Usage: "string\n File name to output results",
},
cli.BoolFlag{
Name: "http2",
Usage: "Send HTTP/2 requests when supported by the server (default false)",
},
}
return app
}
func Action(c *cli.Context) {
app := App()
var headers []attack.Header
if c.String("url") == "None" {
app.Run(os.Args)
return
}
for _, header := range c.StringSlice("header") {
h := headerSplit(header)
if len(h) < 1 {
return
}
headers = append(headers, attack.Header{Key: h[1], Value: h[2]})
}
option := attack.Option{
Concurrency: c.Int("concurrency"),
Requests: c.Int("requests"),
Method: c.String("method"),
URL: c.String("url"),
Header: headers,
Body: c.String("body"),
OutputFile: c.String("output"),
Http2: c.Bool("http2"),
}
benche.Trunks(option)
}
func main() {
app := App()
app.Action = Action
app.Run(os.Args)
}