|
|
|
@ -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 |
|
|
|
|
} |
|
|
|
|