mirror of
https://github.com/cubixle/l1.git
synced 2026-04-24 19:54:47 +01:00
init
This commit is contained in:
0
examples/simple/main.go
Normal file
0
examples/simple/main.go
Normal file
22
l1.go
Normal file
22
l1.go
Normal 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
24
opts.go
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user