fix(registry): ServiceInstance does not implement an Equal method for grpc Attributes. (#2575)

pull/2591/head
Xingwang Liu 2 years ago committed by GitHub
parent e36612e9ca
commit facafba64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 45
      registry/registry.go

@ -1,6 +1,9 @@
package registry package registry
import "context" import (
"context"
"sort"
)
// Registrar is service registrar. // Registrar is service registrar.
type Registrar interface { type Registrar interface {
@ -45,3 +48,43 @@ type ServiceInstance struct {
// grpc://127.0.0.1:9000?isSecure=false // grpc://127.0.0.1:9000?isSecure=false
Endpoints []string `json:"endpoints"` Endpoints []string `json:"endpoints"`
} }
// Equal returns whether i and o are equivalent.
func (i *ServiceInstance) Equal(o interface{}) bool {
if i == nil && o == nil {
return true
}
if i == nil || o == nil {
return false
}
t, ok := o.(*ServiceInstance)
if !ok {
return false
}
if len(i.Endpoints) != len(t.Endpoints) {
return false
}
sort.Strings(i.Endpoints)
sort.Strings(t.Endpoints)
for j := 0; j < len(i.Endpoints); j++ {
if i.Endpoints[j] != t.Endpoints[j] {
return false
}
}
if len(i.Metadata) != len(t.Metadata) {
return false
}
for k, v := range i.Metadata {
if v != t.Metadata[k] {
return false
}
}
return i.ID == t.ID && i.Name == t.Name && i.Version == t.Version
}

Loading…
Cancel
Save