-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.go
50 lines (39 loc) · 821 Bytes
/
generator.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 (
"errors"
"io"
"sync/atomic"
vegeta "github.com/tsenart/vegeta/lib"
)
var (
errNilTarget = errors.New("Nil target")
)
func newTargeter(conf *Config, debugger io.Writer) (vegeta.Targeter, error) {
i := int64(-1)
targets := []*Target{}
for _, t := range conf.Targets {
err := t.parseTemplate()
if err != nil {
return nil, err
}
// Sampling target
for i := 0; i < t.Repeat; i++ {
targets = append(targets, t)
}
}
if !conf.Meta.SkipShuffle {
shuffleRequest(targets)
}
return func(t *vegeta.Target) error {
if t == nil {
return errNilTarget
}
offset := atomic.AddInt64(&i, 1) % int64(len(targets))
selected := targets[offset]
if err := selected.toVegetaTarget(t, nil); err != nil {
return err
}
printDebug(t, debugger)
return nil
}, nil
}