-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
61 lines (52 loc) · 1.69 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
package main
import (
"errors"
"flag"
"log"
"math/rand"
"time"
)
var (
// URLs represents the list of URL to test
URLs = []string{}
// ErrInvalidTrafficType is returned if the traffic type is invalid
ErrInvalidTrafficType = errors.New("invalid traffic type")
nbOfClients int
nbOfRequests int
avgMillisecondsToWait int
fileName string
trafficType string
timeout int
seed int64
followHttpRedirect bool
)
func init() {
// Parse the arguments
flag.IntVar(&nbOfClients, "clients", 10, "number of clients making requests")
flag.IntVar(&nbOfRequests, "requests", 10, "number of requests to be made by each clients")
flag.IntVar(&avgMillisecondsToWait, "wait", 1000, "milliseconds to wait between each requests")
flag.IntVar(&timeout, "timeout", 3, "HTTP timeout in seconds")
flag.Int64Var(&seed, "seed", time.Now().UTC().UnixNano(), "seed for the random")
flag.StringVar(&trafficType, "type", "http", "type of requests http/dns")
flag.StringVar(&fileName, "urlSource", "", "optional filepath where to find the URLs")
flag.BoolVar(&followHttpRedirect, "followRedirect", true, "follow http redirects or not")
flag.Parse()
log.SetFlags(0)
log.Println("Random URLs using seed", seed)
rand.New(rand.NewSource(seed))
}
func main() {
// Create the TrafficGenerator
trafficGenerator, err := NewTrafficGenerator(trafficType)
if err != nil {
log.Fatalf("Error while creating TrafficGenerator: %q", err)
}
// Get the URLs
if err := getURLs(); err != nil {
log.Fatalf("Error while getting the URLs: %q", err)
}
// Generate the traffic
trafficGenerator.Generate()
// Display the statistics
trafficGenerator.DisplayStats()
}