-
Notifications
You must be signed in to change notification settings - Fork 39
/
node_type.go
57 lines (50 loc) · 1022 Bytes
/
node_type.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
package common
import "fmt"
const (
activeSequencer = "sequencer"
validator = "validator"
backupSequencer = "backup_sequencer"
unknown = "unknown"
)
// NodeType represents the type of the node.
type NodeType int
const (
ActiveSequencer NodeType = iota
Validator
BackupSequencer
Unknown
)
func (n NodeType) String() string {
switch n {
case ActiveSequencer:
return activeSequencer
case Validator:
return validator
case BackupSequencer:
return backupSequencer
case Unknown:
return unknown
default:
return unknown
}
}
func (n *NodeType) UnmarshalText(text []byte) error {
nodeType, err := ToNodeType(string(text))
if err != nil {
return err
}
*n = nodeType
return nil
}
func ToNodeType(s string) (NodeType, error) {
switch s {
case activeSequencer:
return ActiveSequencer, nil
case validator:
return Validator, nil
case backupSequencer:
return BackupSequencer, nil
default:
return Unknown, fmt.Errorf("string '%s' cannot be converted to a node type", s)
}
}