-
Notifications
You must be signed in to change notification settings - Fork 8
/
mutator_context.go
57 lines (45 loc) · 1.1 KB
/
mutator_context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package mutators
import (
"context"
"log"
"github.com/mify-io/mify/pkg/workspace"
)
type MutatorContext struct {
logger *log.Logger
ctx context.Context
cancel context.CancelFunc
description *workspace.Description // Description can be null when workspace is not created yet
}
func NewMutatorContext(ctx context.Context, log *log.Logger, description *workspace.Description) *MutatorContext {
ctx, cancel := context.WithCancel(ctx)
return &MutatorContext{
logger: log,
ctx: ctx,
cancel: cancel,
description: description,
}
}
func (c *MutatorContext) GetLogger() *log.Logger {
if c.logger == nil {
panic("Logger is not filled")
}
return c.logger
}
func (c *MutatorContext) GetCtx() context.Context {
if c.ctx == nil {
panic("Ctx is not filled")
}
return c.ctx
}
func (c *MutatorContext) GetCancel() context.CancelFunc {
if c.cancel == nil {
panic("Cancel is not filled")
}
return c.cancel
}
func (c *MutatorContext) GetDescription() *workspace.Description {
if c.description == nil {
panic("Description is not filled")
}
return c.description
}