-
Notifications
You must be signed in to change notification settings - Fork 5
/
factory.go
66 lines (54 loc) · 1.52 KB
/
factory.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
package bus_api_controller
import (
"context"
"github.com/aperturerobotics/controllerbus/bus"
"github.com/aperturerobotics/controllerbus/config"
"github.com/aperturerobotics/controllerbus/controller"
"github.com/blang/semver"
)
// ControllerID identifies the API controller.
const ControllerID = "controllerbus/bus/api"
// Factory constructs a API.
type Factory struct {
// bus is the controller bus
bus bus.Bus
}
// NewFactory builds a bus API factory.
func NewFactory(bus bus.Bus) *Factory {
return &Factory{bus: bus}
}
// GetConfigID returns the unique ID for the config.
func (t *Factory) GetConfigID() string {
return ConfigID
}
// GetControllerID returns the unique ID for the controller.
func (t *Factory) GetControllerID() string {
return ControllerID
}
// ConstructConfig constructs an instance of the controller configuration.
func (t *Factory) ConstructConfig() config.Config {
return &Config{}
}
// Construct constructs the associated controller given configuration.
// The transport's identity (private key) comes from a GetNode lookup.
func (t *Factory) Construct(
ctx context.Context,
conf config.Config,
opts controller.ConstructOpts,
) (controller.Controller, error) {
le := opts.GetLogger()
cc := conf.(*Config)
// Construct the API controller.
return NewController(
le,
cc.GetListenAddr(),
t.bus,
cc,
), nil
}
// GetVersion returns the version of this controller.
func (t *Factory) GetVersion() semver.Version {
return Version
}
// _ is a type assertion
var _ controller.Factory = ((*Factory)(nil))