mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
fix(registry): ServiceInstance does not implement an Equal method for grpc Attributes. (#2575)
This commit is contained in:
parent
e36612e9ca
commit
facafba64a
@ -1,6 +1,9 @@
|
||||
package registry
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// Registrar is service registrar.
|
||||
type Registrar interface {
|
||||
@ -45,3 +48,43 @@ type ServiceInstance struct {
|
||||
// grpc://127.0.0.1:9000?isSecure=false
|
||||
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…
x
Reference in New Issue
Block a user