-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.go
54 lines (44 loc) · 958 Bytes
/
component.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
package starter
import (
"github.com/urfave/cli/v2"
)
type Component interface {
Name() string
Init(ctx *cli.Context) error
Destroy(ctx *cli.Context) error
}
type CompositeComponent struct {
name string
init InitFunc
destroy DestroyFunc
}
type InitFunc func(ctx *cli.Context) error
type DestroyFunc func(ctx *cli.Context) error
func NewComponent(name string) *CompositeComponent {
return &CompositeComponent{
name: name,
}
}
func (c *CompositeComponent) SetInit(f InitFunc) *CompositeComponent {
c.init = f
return c
}
func (c *CompositeComponent) SetDestroy(f DestroyFunc) *CompositeComponent {
c.destroy = f
return c
}
func (c *CompositeComponent) Name() string {
return c.name
}
func (c *CompositeComponent) Init(ctx *cli.Context) error {
if c.init == nil {
return nil
}
return c.init(ctx)
}
func (c *CompositeComponent) Destroy(ctx *cli.Context) error {
if c.destroy == nil {
return nil
}
return c.destroy(ctx)
}