-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunimplemented_module.go
More file actions
58 lines (50 loc) · 1.2 KB
/
unimplemented_module.go
File metadata and controls
58 lines (50 loc) · 1.2 KB
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
58
package platform
import (
"context"
)
// UnimplementedModule implements the module contract.
// The module can embed the type to skip implementing
// any of the bound functions.
type UnimplementedModule struct {
NameFn func() string
StartFn func(context.Context) error
StopFn func(context.Context) error
MountFn func(context.Context, Router) error
}
// NewUnimplementedModule will fill the module name.
func NewUnimplementedModule(name string) *UnimplementedModule {
return &UnimplementedModule{
NameFn: func() string {
return name
},
}
}
// Name returns an empty string.
func (m UnimplementedModule) Name() string {
if m.NameFn != nil {
return m.NameFn()
}
return ""
}
// Start returns nil (no error).
func (m UnimplementedModule) Start(ctx context.Context) error {
if m.StartFn != nil {
return m.StartFn(ctx)
}
return nil
}
// Stop returns nil (no error).
func (m UnimplementedModule) Stop(ctx context.Context) error {
if m.StopFn != nil {
return m.StopFn(ctx)
}
return nil
}
// Mount returns nil (no error).
func (m UnimplementedModule) Mount(ctx context.Context, r Router) error {
if m.MountFn != nil {
return m.MountFn(ctx, r)
}
return nil
}
var _ Module = UnimplementedModule{}