-
Notifications
You must be signed in to change notification settings - Fork 5
/
loader.go
74 lines (62 loc) · 1.91 KB
/
loader.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package loader
import (
"context"
"github.com/aperturerobotics/controllerbus/bus"
"github.com/aperturerobotics/controllerbus/controller"
"github.com/aperturerobotics/controllerbus/directive"
"github.com/blang/semver"
"github.com/sirupsen/logrus"
)
// ControllerID is the controller identifier
const ControllerID = "controllerbus/loader"
// Version is the controller version
var Version = semver.MustParse("0.0.1")
// Controller implements the loader controller.
// It responds to ExecController directives and attaches to a bus.
type Controller struct {
// le is the logger
le *logrus.Entry
// bus is the controller bus
bus bus.Bus
}
// NewController builds a new loader controller given a bus.
// If the given backoff is nil, uses the defaults.
func NewController(le *logrus.Entry, bus bus.Bus) (*Controller, error) {
return &Controller{bus: bus, le: le}, nil
}
// GetControllerInfo returns information about the controller.
func (c *Controller) GetControllerInfo() *controller.Info {
return controller.NewInfo(
ControllerID,
Version,
"controller loader",
)
}
// Execute executes the loader controller.
func (c *Controller) Execute(ctx context.Context) error {
// No-op
return nil
}
// HandleDirective asks if the handler can resolve the directive.
// If it can, it returns a resolver. If not, returns nil.
// Any unexpected errors are returned for logging.
// It is safe to add a reference to the directive during this call.
// The context passed is canceled when the directive instance expires.
func (c *Controller) HandleDirective(
ctx context.Context,
di directive.Instance,
) ([]directive.Resolver, error) {
dir := di.GetDirective()
switch d := dir.(type) {
case ExecController:
return c.resolveExecController(ctx, di, d)
}
return nil, nil
}
// Close closes the controller.
func (c *Controller) Close() error {
// TODO
return nil
}
// _ is a type assertion
var _ controller.Controller = ((*Controller)(nil))