mirror of
https://github.com/cubixle/l1.git
synced 2026-04-24 22:34:45 +01:00
42 lines
684 B
Go
42 lines
684 B
Go
package l1
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// F defines the function type for runners.
|
|
type F func(target string) error
|
|
|
|
// Runner
|
|
type Runner struct {
|
|
MaxConnections int
|
|
MaxParrellConnections int
|
|
Timeout time.Duration
|
|
RunTime time.Duration
|
|
RunFunc F
|
|
Target string
|
|
}
|
|
|
|
func NewRunner(opts ...Opt) (*Runner, error) {
|
|
r := &Runner{
|
|
RunTime: 60 * time.Second,
|
|
Timeout: 30 * time.Second,
|
|
MaxParrellConnections: 10,
|
|
MaxConnections: 10,
|
|
}
|
|
|
|
for _, o := range opts {
|
|
o(r)
|
|
}
|
|
|
|
if r.Target == "" {
|
|
return nil, ErrNoTarget
|
|
}
|
|
|
|
return r, nil
|
|
}
|
|
|
|
func (r *Runner) SetOpt(o Opt) {
|
|
o(r)
|
|
}
|