-
Notifications
You must be signed in to change notification settings - Fork 4
/
controller.go
70 lines (58 loc) · 1.77 KB
/
controller.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
package main
import (
"context"
"github.com/aperturerobotics/controllerbus/controller"
"github.com/aperturerobotics/controllerbus/directive"
"github.com/blang/semver"
"github.com/sirupsen/logrus"
)
// ControllerID is the controller ID.
const ControllerID = "controllerbus/toys/load-controller/controller"
// Version is the controller version.
var Version = semver.MustParse("0.0.1")
// ToyController is an example controller.
type ToyController struct {
// le is the logger
le *logrus.Entry
// conf is the config
conf *ToyControllerConfig
}
// NewToyController constructs a new toy controller.
func NewToyController(le *logrus.Entry, conf *ToyControllerConfig) (*ToyController, error) {
return &ToyController{le: le, conf: conf}, nil
}
// GetControllerInfo returns information about the controller.
func (c *ToyController) GetControllerInfo() *controller.Info {
return controller.NewInfo(
ControllerID,
Version,
"toy controller",
)
}
// HandleDirective asks if the handler can resolve the directive.
func (c *ToyController) HandleDirective(
ctx context.Context,
di directive.Instance,
) ([]directive.Resolver, error) {
// Pass for the example controller
return nil, nil
}
// Execute executes the given controller.
// Returning nil ends execution.
// Returning an error triggers a retry with backoff.
func (c *ToyController) Execute(ctx context.Context) error {
c.le.Debug("toy controller executed")
<-ctx.Done()
return nil
}
// SayHello says hello.
func (c *ToyController) SayHello() {
c.le.Debugf("Hello %s!", c.conf.GetName())
}
// Close releases any resources used by the controller.
// Error indicates any issue encountered releasing.
func (c *ToyController) Close() error {
return nil
}
// _ is a type assertion
var _ controller.Controller = ((*ToyController)(nil))