commit 645ff9d698d158dce6cccf36b5781237f67687c1 Author: cubixle Date: Sat Jul 24 21:09:32 2021 +0100 init diff --git a/examples/simple/main.go b/examples/simple/main.go new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6293577 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/cubixle/l1 + +go 1.16 diff --git a/l1.go b/l1.go new file mode 100644 index 0000000..538f08f --- /dev/null +++ b/l1.go @@ -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 diff --git a/opts.go b/opts.go new file mode 100644 index 0000000..0e42641 --- /dev/null +++ b/opts.go @@ -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 + } +}