Compare commits
2 commits
master
...
feature/10
Author | SHA1 | Date | |
---|---|---|---|
e13edb20cd | |||
e65e4bfe8e |
3 changed files with 33 additions and 3 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
||||||
|
@ -296,7 +297,7 @@ func (x Container) PlacementPolicy() (res netmap.PlacementPolicy) {
|
||||||
//
|
//
|
||||||
// SetAttribute overwrites existing attribute value.
|
// SetAttribute overwrites existing attribute value.
|
||||||
//
|
//
|
||||||
// See also Attribute, IterateAttributes.
|
// See also Attribute, IterateAttributes, IterateUserAttributes.
|
||||||
func (x *Container) SetAttribute(key, value string) {
|
func (x *Container) SetAttribute(key, value string) {
|
||||||
if key == "" {
|
if key == "" {
|
||||||
panic("empty attribute key")
|
panic("empty attribute key")
|
||||||
|
@ -324,7 +325,7 @@ func (x *Container) SetAttribute(key, value string) {
|
||||||
// Attribute reads value of the Container attribute by key. Empty result means
|
// Attribute reads value of the Container attribute by key. Empty result means
|
||||||
// attribute absence.
|
// attribute absence.
|
||||||
//
|
//
|
||||||
// See also SetAttribute, IterateAttributes.
|
// See also SetAttribute, IterateAttributes, IterateUserAttributes.
|
||||||
func (x Container) Attribute(key string) string {
|
func (x Container) Attribute(key string) string {
|
||||||
attrs := x.v2.GetAttributes()
|
attrs := x.v2.GetAttributes()
|
||||||
for i := range attrs {
|
for i := range attrs {
|
||||||
|
@ -347,6 +348,21 @@ func (x Container) IterateAttributes(f func(key, val string)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IterateUserAttributes iterates over user Container attributes and passes them
|
||||||
|
// into f. The handler MUST NOT be nil.
|
||||||
|
//
|
||||||
|
// See also SetAttribute, Attribute.
|
||||||
|
func (x Container) IterateUserAttributes(f func(key, val string)) {
|
||||||
|
attrs := x.v2.GetAttributes()
|
||||||
|
for _, attr := range attrs {
|
||||||
|
var key = attr.GetKey()
|
||||||
|
if !strings.HasPrefix(key, container.SysAttributePrefix) &&
|
||||||
|
!strings.HasPrefix(key, container.SysAttributePrefixNeoFS) {
|
||||||
|
f(key, attr.GetValue())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetName sets human-readable name of the Container. Name MUST NOT be empty.
|
// SetName sets human-readable name of the Container. Name MUST NOT be empty.
|
||||||
//
|
//
|
||||||
// See also Name.
|
// See also Name.
|
||||||
|
|
|
@ -150,7 +150,7 @@ func assertContainsAttribute(t *testing.T, m v2container.Container, key, val str
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainer_Attribute(t *testing.T) {
|
func TestContainer_Attribute(t *testing.T) {
|
||||||
const attrKey1, attrKey2 = "key1", "key2"
|
const attrKey1, attrKey2 = v2container.SysAttributePrefix + "key1", v2container.SysAttributePrefixNeoFS + "key2"
|
||||||
const attrVal1, attrVal2 = "val1", "val2"
|
const attrVal1, attrVal2 = "val1", "val2"
|
||||||
|
|
||||||
val := containertest.Container()
|
val := containertest.Container()
|
||||||
|
@ -158,6 +158,12 @@ func TestContainer_Attribute(t *testing.T) {
|
||||||
val.SetAttribute(attrKey1, attrVal1)
|
val.SetAttribute(attrKey1, attrVal1)
|
||||||
val.SetAttribute(attrKey2, attrVal2)
|
val.SetAttribute(attrKey2, attrVal2)
|
||||||
|
|
||||||
|
var i int
|
||||||
|
val.IterateUserAttributes(func(key, val string) {
|
||||||
|
i++
|
||||||
|
})
|
||||||
|
require.Equal(t, 1, i)
|
||||||
|
|
||||||
var msg v2container.Container
|
var msg v2container.Container
|
||||||
val.WriteToV2(&msg)
|
val.WriteToV2(&msg)
|
||||||
|
|
||||||
|
|
|
@ -169,3 +169,11 @@ func (x *Address) DecodeString(s string) error {
|
||||||
func (x Address) String() string {
|
func (x Address) String() string {
|
||||||
return x.EncodeToString()
|
return x.EncodeToString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Equals defines a comparison relation between two Address's instances.
|
||||||
|
//
|
||||||
|
// Note that comparison using '==' operator is not recommended since it MAY result
|
||||||
|
// in loss of compatibility.
|
||||||
|
func (x Address) Equals(other Address) bool {
|
||||||
|
return x.obj.Equals(other.obj) && x.cnr.Equals(other.cnr)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue