forked from TrueCloudLab/frostfs-api-go
[#302] pkg/container: Convert nil Attributes
to nil message
Make `Attributes.ToV2` method to return `nil` when called on `nil`. Make `NewAttributesFromV2` function to return `nil` when called on `nil`. Write corresponding unit tests. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
f92f9cd424
commit
0206bd9a5d
3 changed files with 18 additions and 2 deletions
|
@ -50,6 +50,10 @@ func (a *Attribute) ToV2() *container.Attribute {
|
|||
}
|
||||
|
||||
func NewAttributesFromV2(v []*container.Attribute) Attributes {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
attrs := make(Attributes, 0, len(v))
|
||||
for i := range v {
|
||||
attrs = append(attrs, NewAttributeFromV2(v[i]))
|
||||
|
@ -59,6 +63,10 @@ func NewAttributesFromV2(v []*container.Attribute) Attributes {
|
|||
}
|
||||
|
||||
func (a Attributes) ToV2() []*container.Attribute {
|
||||
if a == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
attrs := make([]*container.Attribute, 0, len(a))
|
||||
for i := range a {
|
||||
attrs = append(attrs, a[i].ToV2())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue