From 645ff9d698d158dce6cccf36b5781237f67687c1 Mon Sep 17 00:00:00 2001 From: cubixle Date: Sat, 24 Jul 2021 21:09:32 +0100 Subject: [PATCH] init --- examples/simple/main.go | 0 go.mod | 3 +++ l1.go | 22 ++++++++++++++++++++++ opts.go | 24 ++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 examples/simple/main.go create mode 100644 go.mod create mode 100644 l1.go create mode 100644 opts.go 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 + } +}