This commit is contained in:
cubixle
2021-07-24 21:09:32 +01:00
commit 645ff9d698
4 changed files with 49 additions and 0 deletions

0
examples/simple/main.go Normal file
View File

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/cubixle/l1
go 1.16

22
l1.go Normal file
View File

@@ -0,0 +1,22 @@
package l1
import "time"
// Runner
type Runner struct {
MaxConnections int
Timeout int
RunTime time.Duration
}
func NewRunner(opts ...Opt) {
r := &Runner{
RunTime: 60 * time.Second,
}
for _, o := range opts {
o(r)
}
}
// F defines the function type for runners.
type F func(url string) error

24
opts.go Normal file
View File

@@ -0,0 +1,24 @@
package l1
import "time"
// Opt
type Opt func(*Runner)
func WithMaxConns(amount int) Opt {
return func(r *Runner) {
r.MaxConnections = amount
}
}
func WithTimeout(s int) Opt {
return func(r *Runner) {
r.Timeout = s
}
}
func WithRunTime(timeInSecs int) Opt {
return func(r *Runner) {
r.RunTime = time.Duration(timeInSecs) * time.Second
}
}