-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.go
62 lines (52 loc) · 1.82 KB
/
config.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
package websocket
import (
"github.com/aperturerobotics/bifrost/peer"
"github.com/aperturerobotics/bifrost/transport"
"github.com/aperturerobotics/bifrost/util/confparse"
"github.com/aperturerobotics/controllerbus/config"
"github.com/pkg/errors"
)
// ConfigID is the string used to identify this config object.
const ConfigID = ControllerID
// Validate validates the configuration.
// This is a cursory validation to see if the values "look correct."
func (c *Config) Validate() error {
if _, err := c.ParseTransportPeerID(); err != nil {
return errors.Wrap(err, "node_peer_id")
}
return nil
}
// ParseTransportPeerID parses the node peer ID if it is not empty.
func (c *Config) ParseTransportPeerID() (peer.ID, error) {
return confparse.ParsePeerID(c.GetTransportPeerId())
}
// GetConfigID returns the unique string for this configuration type.
// This string is stored with the encoded config.
func (c *Config) GetConfigID() string {
return ConfigID
}
// EqualsConfig checks if the other config is equal.
func (c *Config) EqualsConfig(c2 config.Config) bool {
return config.EqualsConfig[*Config](c, c2)
}
// SetTransportPeerId sets the node peer ID field.
func (c *Config) SetTransportPeerId(peerID string) {
c.TransportPeerId = peerID
}
// GetDebugVals returns the directive arguments as key/value pairs.
// This should be something like param1="test", param2="test".
// This is not necessarily unique, and is primarily intended for display.
func (c *Config) GetDebugVals() config.DebugValues {
vals := make(config.DebugValues)
if tp := c.GetTransportPeerId(); tp != "" {
vals["peer-id"] = []string{tp}
}
if la := c.GetListenAddr(); la != "" {
vals["listen-addr"] = []string{la}
}
return vals
}
// _ is a type assertion
var _ transport.Config = ((*Config)(nil))
// _ is a type assertion
var _ config.Debuggable = ((*Config)(nil))