diff --git a/pkg/object/type.go b/pkg/object/type.go index afcbdf28..fde1aaa0 100644 --- a/pkg/object/type.go +++ b/pkg/object/type.go @@ -33,3 +33,14 @@ func TypeFromV2(t object.Type) Type { return TypeRegular } } + +func (t Type) String() string { + return t.ToV2().String() +} + +// TypeFromString parses Type from its string representation. +func TypeFromString(s string) Type { + return TypeFromV2( + object.TypeFromString(s), + ) +} diff --git a/pkg/object/type_test.go b/pkg/object/type_test.go index 82f8bf22..7ade2ef4 100644 --- a/pkg/object/type_test.go +++ b/pkg/object/type_test.go @@ -34,3 +34,13 @@ func TestType_ToV2(t *testing.T) { require.Equal(t, item.t, TypeFromV2(item.t2)) } } + +func TestType_String(t *testing.T) { + for _, typ := range []Type{ + TypeRegular, + TypeTombstone, + TypeStorageGroup, + } { + require.Equal(t, typ, TypeFromString(typ.String())) + } +} diff --git a/v2/object/string.go b/v2/object/string.go new file mode 100644 index 00000000..ad82a124 --- /dev/null +++ b/v2/object/string.go @@ -0,0 +1,29 @@ +package object + +const ( + typeRegularString = "Regular" + typeTombstoneString = "Tombstone" + typeStorageGroupString = "StorageGroup" +) + +func (t Type) String() string { + switch t { + default: + return typeRegularString + case TypeTombstone: + return typeTombstoneString + case TypeStorageGroup: + return typeStorageGroupString + } +} + +func TypeFromString(s string) Type { + switch s { + default: + return TypeRegular + case typeTombstoneString: + return TypeTombstone + case typeStorageGroupString: + return TypeStorageGroup + } +}