Skip to content

Commit

Permalink
Value->unexported
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed Oct 15, 2021
1 parent a2868a2 commit 8e8e295
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
22 changes: 9 additions & 13 deletions attributes/attributes.go
Expand Up @@ -28,18 +28,13 @@ package attributes
// Attributes is an immutable struct for storing and retrieving generic
// key/value pairs. Keys must be hashable, and users should define their own
// types for keys. Values should not be modified after they are added to an
// Attributes or if they were received from one.
// Attributes or if they were received from one. If values implement 'Equal(o
// interface{}) bool', it will be called by (*Attributes).Equal to determine
// whether two values with the same key should be considered equal.
type Attributes struct {
m map[interface{}]interface{}
}

// Value may be implemented by all values stored in Attributes. It allows
// comparing the values with other attributes matching the same key.
type Value interface {
// Equal returns whether this Value is equivalent to o.
Equal(o interface{}) bool
}

// New returns a new Attributes containing the key/value pair.
func New(key, value interface{}) *Attributes {
return &Attributes{m: map[interface{}]interface{}{key: value}}
Expand Down Expand Up @@ -70,10 +65,11 @@ func (a *Attributes) Value(key interface{}) interface{} {
return a.m[key]
}

// Equal returns whether a and o are equivalent. If Value is implemented for a
// value in the attributes, it is called to determine if the value matches the
// one stored in the other attributes. If Value is not implemented, standard
// equality is used to determine if the two values are equal.
// Equal returns whether a and o are equivalent. If 'Equal(o interface{})
// bool' is implemented for a value in the attributes, it is called to
// determine if the value matches the one stored in the other attributes. If
// Equal is not implemented, standard equality is used to determine if the two
// values are equal.
func (a *Attributes) Equal(o *Attributes) bool {
if a == nil && o == nil {
return true
Expand All @@ -90,7 +86,7 @@ func (a *Attributes) Equal(o *Attributes) bool {
// o missing element of a
return false
}
if eq, ok := v.(Value); ok {
if eq, ok := v.(interface{ Equal(o interface{}) bool }); ok {
if !eq.Equal(ov) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion balancer/weightedroundrobin/weightedroundrobin.go
Expand Up @@ -36,7 +36,7 @@ type AddrInfo struct {
Weight uint32
}

// Equal satisfies attributes.Value.
// Equal allows the values to be compared by Attributes.Equal.
func (a AddrInfo) Equal(o interface{}) bool {
oa, ok := o.(AddrInfo)
return ok && oa.Weight == a.Weight
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/internal.go
Expand Up @@ -46,7 +46,7 @@ func (l LocalityID) ToString() (string, error) {
return string(b), nil
}

// Equal satisfies attributes.Value.
// Equal allows the values to be compared by Attributes.Equal.
func (l LocalityID) Equal(o interface{}) bool {
ol, ok := o.(LocalityID)
if !ok {
Expand Down

0 comments on commit 8e8e295

Please sign in to comment.