aboutsummaryrefslogtreecommitdiff
path: root/mixins.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <alexander@kiryukhin.su>2019-03-27 02:44:38 +0300
committerAlexander Kiryukhin <alexander@kiryukhin.su>2019-03-27 02:44:38 +0300
commitd45d913c9e0d088f339c007f14d2fcaa7b9c8c74 (patch)
tree486d43d7359b5842f6f34b814764389fa27640d2 /mixins.go
parent11a32ca219905f7c42698b55b6af9920626b7b51 (diff)
Flexible run policiesv0.3.0
Options refactoring
Diffstat (limited to 'mixins.go')
-rwxr-xr-xmixins.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/mixins.go b/mixins.go
new file mode 100755
index 0000000..65309e4
--- /dev/null
+++ b/mixins.go
@@ -0,0 +1,41 @@
+package rutina
+
+import (
+ "context"
+ "log"
+ "os"
+)
+
+type Mixin interface {
+ apply(*Rutina)
+}
+
+type MixinContext struct {
+ Context context.Context
+}
+
+func WithContext(context context.Context) *MixinContext {
+ return &MixinContext{Context: context}
+}
+
+func (o MixinContext) apply(r *Rutina) {
+ ctx, cancel := context.WithCancel(o.Context)
+ r.ctx = ctx
+ r.Cancel = cancel
+}
+
+type MixinLogger struct {
+ Logger *log.Logger
+}
+
+func WithLogger(logger *log.Logger) *MixinLogger {
+ return &MixinLogger{Logger: logger}
+}
+
+func WithStdLogger() *MixinLogger {
+ return &MixinLogger{Logger: log.New(os.Stdout, "rutina", log.LstdFlags)}
+}
+
+func (o MixinLogger) apply(r *Rutina) {
+ r.logger = o.Logger
+}