forked from tsenart/vegeta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (41 loc) · 890 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
)
// command is a closure function which each command constructor
// builds and returns
type command func() error
var usage = fmt.Sprintf(
`Usage: vegeta [globals] <command> [options]
Commands:
attack Hit the targets
report Report the results
Globals:
-cpus=%d Number of CPUs to use
`, runtime.NumCPU())
func init() {
flag.Usage = func() { fmt.Print(usage) }
cpus := flag.Int("cpus", runtime.NumCPU(), "Number of CPUs to use")
flag.Parse()
runtime.GOMAXPROCS(*cpus)
}
func main() {
commands := map[string]func([]string) command{
"attack": attackCmd,
"report": reportCmd,
}
args := flag.Args()
if len(args) == 0 {
flag.Usage()
os.Exit(1)
}
if cmd, ok := commands[args[0]]; !ok {
log.Fatalf("Unknown command: %s", args[0])
} else if err := cmd(args[1:])(); err != nil {
log.Fatal(err)
}
}