-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
71 lines (62 loc) · 2.01 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
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"runtime"
"strings"
)
type Config struct {
Port string
Nodes []string
}
var (
numThreads = flag.Int("t", 1, "the numbers of threads used")
requestBody = flag.String("b", "", "the request body")
requestBodyFile = flag.String("p", "", "the request body data file")
requestBodyHex = flag.Bool("hex", false, "the request body using hex coding")
addLenField = flag.Bool("addlen", true, "auto add 2 byte field to index body length")
headerlen = flag.Int("headerlen", 0, "n byte msg header")
numConnections = flag.Int("c", 1, "the max numbers of connections used")
totalCalls = flag.Int("n", 1, "the total number of calls processed")
disableKeepAlives = flag.Bool("k", true, "if keep-alives are disabled")
certFile = flag.String("cert", "someCertFile", "A PEM eoncoded certificate file.")
keyFile = flag.String("key", "someKeyFile", "A PEM encoded private key file.")
caFile = flag.String("CA", "someCertCAFile", "A PEM eoncoded CA's certificate file.")
insecure = flag.Bool("i", false, "TLS checks are disabled")
printMsg = flag.Bool("print", false, "print all in and out msg")
msgSize = flag.Int("size", -1, "msg size to calc Mbps")
target string
)
func init() {
flag.Parse()
target = os.Args[len(os.Args)-1]
runtime.GOMAXPROCS(*numThreads) //一个gorotine 一个连接, 设置线程最大数量是为了限制同时运行的gorotine
}
func setRequestBody() {
// requestBody has been setup and it has highest priority
if *requestBody != "" {
return
}
if *requestBodyFile == "" {
return
}
// requestBodyFile has been setup
data, err := ioutil.ReadFile(*requestBodyFile)
if err != nil {
fmt.Println(err)
panic(err)
}
body := string(data)
body = strings.TrimSpace(body)
requestBody = &body
}
func main() {
if len(os.Args) == 1 { //If no argument specified
flag.Usage() //Print usage
os.Exit(1)
}
setRequestBody()
SingleNode(target)
}