diff options
Diffstat (limited to 'mixins.go')
-rwxr-xr-x | mixins.go | 41 |
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 +} |