NewAttacker returns a new Attacker with default options which are overridden by the optionally provided opts.
(opts ...func(*Attacker))
| 68 | // NewAttacker returns a new Attacker with default options which are overridden |
| 69 | // by the optionally provided opts. |
| 70 | func NewAttacker(opts ...func(*Attacker)) *Attacker { |
| 71 | a := &Attacker{ |
| 72 | stopch: make(chan struct{}), |
| 73 | stopOnce: sync.Once{}, |
| 74 | workers: DefaultWorkers, |
| 75 | maxWorkers: DefaultMaxWorkers, |
| 76 | maxBody: DefaultMaxBody, |
| 77 | } |
| 78 | |
| 79 | a.dialer = &net.Dialer{ |
| 80 | LocalAddr: &net.TCPAddr{IP: DefaultLocalAddr.IP, Zone: DefaultLocalAddr.Zone}, |
| 81 | KeepAlive: 30 * time.Second, |
| 82 | } |
| 83 | |
| 84 | a.client = http.Client{ |
| 85 | Timeout: DefaultTimeout, |
| 86 | Transport: &http.Transport{ |
| 87 | Proxy: http.ProxyFromEnvironment, |
| 88 | DialContext: a.dialer.DialContext, |
| 89 | TLSClientConfig: DefaultTLSConfig, |
| 90 | MaxIdleConnsPerHost: DefaultConnections, |
| 91 | MaxConnsPerHost: DefaultMaxConnections, |
| 92 | }, |
| 93 | } |
| 94 | |
| 95 | for _, opt := range opts { |
| 96 | opt(a) |
| 97 | } |
| 98 | |
| 99 | return a |
| 100 | } |
| 101 | |
| 102 | // Workers returns a functional option which sets the initial number of workers |
| 103 | // an Attacker uses to hit its targets. More workers may be spawned dynamically |
no outgoing calls