-
Notifications
You must be signed in to change notification settings - Fork 8
/
factory.go
68 lines (55 loc) · 1.49 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
67
68
package peer_controller
import (
"errors"
"github.com/aperturerobotics/controllerbus/config"
"github.com/aperturerobotics/controllerbus/controller"
"github.com/blang/semver"
)
// Factory constructs a Peer controller.
type Factory struct {
}
// NewFactory builds a peer controller factory.
func NewFactory() *Factory {
return &Factory{}
}
// GetConfigID returns the configuration ID for the controller.
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.
func (t *Factory) Construct(
conf config.Config,
opts controller.ConstructOpts,
) (controller.Controller, error) {
le := opts.GetLogger()
cc := conf.(*Config)
privKey, err := cc.ParsePrivateKey()
if err != nil {
return nil, err
}
if privKey == nil {
return nil, errors.New("private key must be configured")
/*
le.Info("generating private key, none configured")
privKey, _, err = keypem.GeneratePrivKey()
if err != nil {
return nil, err
}
*/
}
return NewController(le, privKey)
}
// GetVersion returns the version of this controller.
func (t *Factory) GetVersion() semver.Version {
return Version
}
// _ is a type assertion
var _ controller.Factory = ((*Factory)(nil))