forked from TrueCloudLab/frostfs-api-go
[#310] *: Implement string converters for enumerations
Implement `String` / `FromString` method pair in all levels of enum definitions. From now `String()` returns canonical protojson-compatible values. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
fdea892db7
commit
616b4b71a1
25 changed files with 1053 additions and 76 deletions
|
@ -176,15 +176,30 @@ func (s NodeState) ToV2() netmap.NodeState {
|
|||
}
|
||||
}
|
||||
|
||||
// String returns string representation of NodeState.
|
||||
//
|
||||
// String mapping:
|
||||
// * NodeStateOnline: ONLINE;
|
||||
// * NodeStateOffline: OFFLINE;
|
||||
// * default: UNSPECIFIED.
|
||||
func (s NodeState) String() string {
|
||||
switch s {
|
||||
default:
|
||||
return "STATE_UNSPECIFIED"
|
||||
case NodeStateOffline:
|
||||
return "OFFLINE"
|
||||
case NodeStateOnline:
|
||||
return "ONLINE"
|
||||
return s.ToV2().String()
|
||||
}
|
||||
|
||||
// FromString parses NodeState from a string representation.
|
||||
// It is a reverse action to String().
|
||||
//
|
||||
// Returns true if s was parsed successfully.
|
||||
func (s *NodeState) FromString(str string) bool {
|
||||
var g netmap.NodeState
|
||||
|
||||
ok := g.FromString(str)
|
||||
|
||||
if ok {
|
||||
*s = NodeStateFromV2(g)
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
// NewNodeAttribute creates and returns new NodeAttribute instance.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue