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
26
v2/refs/string.go
Normal file
26
v2/refs/string.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package refs
|
||||
|
||||
import (
|
||||
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
||||
)
|
||||
|
||||
// String returns string representation of ChecksumType.
|
||||
func (t ChecksumType) String() string {
|
||||
return ChecksumTypeToGRPC(t).String()
|
||||
}
|
||||
|
||||
// FromString parses ChecksumType from a string representation.
|
||||
// It is a reverse action to String().
|
||||
//
|
||||
// Returns true if s was parsed successfully.
|
||||
func (t *ChecksumType) FromString(s string) bool {
|
||||
var g refs.ChecksumType
|
||||
|
||||
ok := g.FromString(s)
|
||||
|
||||
if ok {
|
||||
*t = ChecksumTypeFromGRPC(g)
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue