* PoC: memory registry using maps instead of slice madness * Updated proto and handlers. Fixed tests across codebase. * Implemented ttl pruning for memory registry * Added extensive memory registry tests * Squased a bunch of bugs * Proto indent; memory.Registry.String() returns "memory" * Write a test to prove memory registry TTLs are busted Signed-off-by: Erik Hollensbe <github@hollensbe.org> * Additional memory testing and fixups: * DefaultTTL removed * When TTL == 0, it is automatically removed from expiry conditions * Additional improvements to new tests Signed-off-by: Erik Hollensbe <github@hollensbe.org>
This commit is contained in:
committed by
Asim Aslam
parent
97c1300f53
commit
4107733453
@@ -3,7 +3,6 @@ package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -14,23 +13,29 @@ import (
|
||||
|
||||
var (
|
||||
sendEventTime = 10 * time.Millisecond
|
||||
ttlPruneTime = 1 * time.Minute
|
||||
DefaultTTL = 1 * time.Minute
|
||||
ttlPruneTime = time.Second
|
||||
)
|
||||
|
||||
// node tracks node registration timestamp and TTL
|
||||
type node struct {
|
||||
lastSeen time.Time
|
||||
ttl time.Duration
|
||||
*registry.Node
|
||||
TTL time.Duration
|
||||
LastSeen time.Time
|
||||
}
|
||||
|
||||
type record struct {
|
||||
Name string
|
||||
Version string
|
||||
Metadata map[string]string
|
||||
Nodes map[string]*node
|
||||
Endpoints []*registry.Endpoint
|
||||
}
|
||||
|
||||
type Registry struct {
|
||||
options registry.Options
|
||||
|
||||
sync.RWMutex
|
||||
Services map[string][]*registry.Service
|
||||
nodes map[string]*node
|
||||
Watchers map[string]*Watcher
|
||||
records map[string]map[string]*record
|
||||
watchers map[string]*Watcher
|
||||
}
|
||||
|
||||
func NewRegistry(opts ...registry.Option) registry.Registry {
|
||||
@@ -42,16 +47,15 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
services := getServices(options.Context)
|
||||
if services == nil {
|
||||
services = make(map[string][]*registry.Service)
|
||||
records := getServiceRecords(options.Context)
|
||||
if records == nil {
|
||||
records = make(map[string]map[string]*record)
|
||||
}
|
||||
|
||||
reg := &Registry{
|
||||
options: options,
|
||||
Services: services,
|
||||
nodes: make(map[string]*node),
|
||||
Watchers: make(map[string]*Watcher),
|
||||
records: records,
|
||||
watchers: make(map[string]*Watcher),
|
||||
}
|
||||
|
||||
go reg.ttlPrune()
|
||||
@@ -59,11 +63,6 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
|
||||
return reg
|
||||
}
|
||||
|
||||
// nodeTrackId returns a string we use to track a node of a given service
|
||||
func nodeTrackId(svcName, svcVersion, nodeId string) string {
|
||||
return svcName + "+" + svcVersion + "+" + nodeId
|
||||
}
|
||||
|
||||
func (m *Registry) ttlPrune() {
|
||||
prune := time.NewTicker(ttlPruneTime)
|
||||
defer prune.Stop()
|
||||
@@ -72,49 +71,26 @@ func (m *Registry) ttlPrune() {
|
||||
select {
|
||||
case <-prune.C:
|
||||
m.Lock()
|
||||
for nodeTrackId, node := range m.nodes {
|
||||
// if the TTL has been set and we exceed the hresholdset by it we stop tracking the node
|
||||
if node.ttl.Seconds() != 0.0 && time.Since(node.lastSeen) > node.ttl {
|
||||
// split nodeTrackID into service Name, Version and Node Id
|
||||
trackIdSplit := strings.Split(nodeTrackId, "+")
|
||||
svcName, svcVersion, nodeId := trackIdSplit[0], trackIdSplit[1], trackIdSplit[2]
|
||||
log.Debugf("[memory] Registry TTL expired for service %s, node %s", svcName, nodeId)
|
||||
// we need to find a node that expired and delete it from service nodes
|
||||
if _, ok := m.Services[svcName]; ok {
|
||||
for _, service := range m.Services[svcName] {
|
||||
if service.Version != svcVersion {
|
||||
continue
|
||||
}
|
||||
// find expired service node and delete it
|
||||
var nodes []*registry.Node
|
||||
for _, n := range service.Nodes {
|
||||
var del bool
|
||||
if n.Id == nodeId {
|
||||
del = true
|
||||
}
|
||||
if !del {
|
||||
nodes = append(nodes, n)
|
||||
}
|
||||
}
|
||||
service.Nodes = nodes
|
||||
for name, records := range m.records {
|
||||
for version, record := range records {
|
||||
for id, n := range record.Nodes {
|
||||
if n.TTL != 0 && time.Since(n.LastSeen) > n.TTL {
|
||||
log.Debugf("Registry TTL expired for node %s of service %s", n.Id, name)
|
||||
delete(m.records[name][version].Nodes, id)
|
||||
}
|
||||
}
|
||||
// stop tracking the node
|
||||
delete(m.nodes, nodeTrackId)
|
||||
}
|
||||
}
|
||||
m.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Registry) sendEvent(r *registry.Result) {
|
||||
watchers := make([]*Watcher, 0, len(m.Watchers))
|
||||
watchers := make([]*Watcher, 0, len(m.watchers))
|
||||
|
||||
m.RLock()
|
||||
for _, w := range m.Watchers {
|
||||
for _, w := range m.watchers {
|
||||
watchers = append(watchers, w)
|
||||
}
|
||||
m.RUnlock()
|
||||
@@ -123,7 +99,7 @@ func (m *Registry) sendEvent(r *registry.Result) {
|
||||
select {
|
||||
case <-w.exit:
|
||||
m.Lock()
|
||||
delete(m.Watchers, w.id)
|
||||
delete(m.watchers, w.id)
|
||||
m.Unlock()
|
||||
default:
|
||||
select {
|
||||
@@ -141,11 +117,24 @@ func (m *Registry) Init(opts ...registry.Option) error {
|
||||
|
||||
// add services
|
||||
m.Lock()
|
||||
for k, v := range getServices(m.options.Context) {
|
||||
s := m.Services[k]
|
||||
m.Services[k] = registry.Merge(s, v)
|
||||
defer m.Unlock()
|
||||
|
||||
records := getServiceRecords(m.options.Context)
|
||||
for name, record := range records {
|
||||
// add a whole new service including all of its versions
|
||||
if _, ok := m.records[name]; !ok {
|
||||
m.records[name] = record
|
||||
continue
|
||||
}
|
||||
// add the versions of the service we dont track yet
|
||||
for version, r := range record {
|
||||
if _, ok := m.records[name][version]; !ok {
|
||||
m.records[name][version] = r
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
m.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -153,104 +142,61 @@ func (m *Registry) Options() registry.Options {
|
||||
return m.options
|
||||
}
|
||||
|
||||
func (m *Registry) GetService(name string) ([]*registry.Service, error) {
|
||||
m.RLock()
|
||||
service, ok := m.Services[name]
|
||||
m.RUnlock()
|
||||
if !ok {
|
||||
return nil, registry.ErrNotFound
|
||||
}
|
||||
|
||||
return service, nil
|
||||
}
|
||||
|
||||
func (m *Registry) ListServices() ([]*registry.Service, error) {
|
||||
var services []*registry.Service
|
||||
m.RLock()
|
||||
for _, service := range m.Services {
|
||||
services = append(services, service...)
|
||||
}
|
||||
m.RUnlock()
|
||||
return services, nil
|
||||
}
|
||||
|
||||
func (m *Registry) Register(s *registry.Service, opts ...registry.RegisterOption) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
log.Debugf("[memory] Registry registering service: %s", s.Name)
|
||||
|
||||
var options registry.RegisterOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if service, ok := m.Services[s.Name]; !ok {
|
||||
m.Services[s.Name] = []*registry.Service{s}
|
||||
// add all nodes into nodes map to track their TTL
|
||||
for _, n := range s.Nodes {
|
||||
log.Debugf("[memory] Registry tracking new service: %s, node %s", s.Name, n.Id)
|
||||
m.nodes[nodeTrackId(s.Name, s.Version, n.Id)] = &node{
|
||||
lastSeen: time.Now(),
|
||||
ttl: options.TTL,
|
||||
}
|
||||
}
|
||||
r := serviceToRecord(s, options.TTL)
|
||||
|
||||
if _, ok := m.records[s.Name]; !ok {
|
||||
m.records[s.Name] = make(map[string]*record)
|
||||
}
|
||||
|
||||
if _, ok := m.records[s.Name][s.Version]; !ok {
|
||||
m.records[s.Name][s.Version] = r
|
||||
log.Debugf("Registry added new service: %s, version: %s", s.Name, s.Version)
|
||||
go m.sendEvent(®istry.Result{Action: "update", Service: s})
|
||||
return nil
|
||||
} else {
|
||||
// svcCount keeps the count of all versions of particular service
|
||||
//svcCount := len(service)
|
||||
// svcNodes maintains a list of node Ids per particular service version
|
||||
svcNodes := make(map[string]map[string][]string)
|
||||
// collect all service ids for all service versions
|
||||
for _, s := range service {
|
||||
if _, ok := svcNodes[s.Name]; !ok {
|
||||
svcNodes[s.Name] = make(map[string][]string)
|
||||
}
|
||||
if _, ok := svcNodes[s.Name][s.Version]; !ok {
|
||||
for _, n := range s.Nodes {
|
||||
svcNodes[s.Name][s.Version] = append(svcNodes[s.Name][s.Version], n.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
// if merged count and original service counts changed we know we are adding a new version of the service
|
||||
merged := registry.Merge(service, []*registry.Service{s})
|
||||
// if the node count of any service [version] changed we know we are adding a new node to the service
|
||||
for _, s := range merged {
|
||||
// we know that if the node counts have changed we need to track new nodes
|
||||
if len(s.Nodes) != len(svcNodes[s.Name][s.Version]) {
|
||||
for _, n := range s.Nodes {
|
||||
var found bool
|
||||
for _, id := range svcNodes[s.Name][s.Version] {
|
||||
if n.Id == id {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
log.Debugf("[memory] Registry tracking new node: %s for service %s", n.Id, s.Name)
|
||||
m.nodes[nodeTrackId(s.Name, s.Version, n.Id)] = &node{
|
||||
lastSeen: time.Now(),
|
||||
ttl: options.TTL,
|
||||
}
|
||||
}
|
||||
}
|
||||
m.Services[s.Name] = merged
|
||||
go m.sendEvent(®istry.Result{Action: "update", Service: s})
|
||||
return nil
|
||||
}
|
||||
// refresh the timestamp and TTL of the service node
|
||||
for _, n := range s.Nodes {
|
||||
trackId := nodeTrackId(s.Name, s.Version, n.Id)
|
||||
log.Debugf("[memory] Registry refreshing TTL for node %s for service %s", n.Id, s.Name)
|
||||
if trackedNode, ok := m.nodes[trackId]; ok {
|
||||
trackedNode.lastSeen = time.Now()
|
||||
trackedNode.ttl = options.TTL
|
||||
}
|
||||
|
||||
addedNodes := false
|
||||
for _, n := range s.Nodes {
|
||||
if _, ok := m.records[s.Name][s.Version].Nodes[n.Id]; !ok {
|
||||
addedNodes = true
|
||||
metadata := make(map[string]string)
|
||||
for k, v := range n.Metadata {
|
||||
metadata[k] = v
|
||||
m.records[s.Name][s.Version].Nodes[n.Id] = &node{
|
||||
Node: ®istry.Node{
|
||||
Id: n.Id,
|
||||
Address: n.Address,
|
||||
Metadata: metadata,
|
||||
},
|
||||
TTL: options.TTL,
|
||||
LastSeen: time.Now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if addedNodes {
|
||||
log.Debugf("Registry added new node to service: %s, version: %s", s.Name, s.Version)
|
||||
go m.sendEvent(®istry.Result{Action: "update", Service: s})
|
||||
return nil
|
||||
}
|
||||
|
||||
// refresh TTL and timestamp
|
||||
for _, n := range s.Nodes {
|
||||
log.Debugf("Updated registration for service: %s, version: %s", s.Name, s.Version)
|
||||
m.records[s.Name][s.Version].Nodes[n.Id].TTL = options.TTL
|
||||
m.records[s.Name][s.Version].Nodes[n.Id].LastSeen = time.Now()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -258,57 +204,62 @@ func (m *Registry) Deregister(s *registry.Service) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
log.Debugf("[memory] Registry deregistering service: %s", s.Name)
|
||||
|
||||
if service, ok := m.Services[s.Name]; ok {
|
||||
// svcNodes collects the list of all node Ids for each service version
|
||||
svcNodes := make(map[string]map[string][]string)
|
||||
// collect all service node ids for all service versions
|
||||
for _, svc := range service {
|
||||
if _, ok := svcNodes[svc.Name]; !ok {
|
||||
svcNodes[svc.Name] = make(map[string][]string)
|
||||
}
|
||||
if _, ok := svcNodes[svc.Name][svc.Version]; !ok {
|
||||
for _, n := range svc.Nodes {
|
||||
svcNodes[svc.Name][svc.Version] = append(svcNodes[svc.Name][svc.Version], n.Id)
|
||||
if _, ok := m.records[s.Name]; ok {
|
||||
if _, ok := m.records[s.Name][s.Version]; ok {
|
||||
for _, n := range s.Nodes {
|
||||
if _, ok := m.records[s.Name][s.Version].Nodes[n.Id]; ok {
|
||||
log.Debugf("Registry removed node from service: %s, version: %s", s.Name, s.Version)
|
||||
delete(m.records[s.Name][s.Version].Nodes, n.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
// if there are no more services we know we have either removed all nodes or there were no nodes
|
||||
if updatedService := registry.Remove(service, []*registry.Service{s}); len(updatedService) == 0 {
|
||||
for _, id := range svcNodes[s.Name][s.Version] {
|
||||
log.Debugf("[memory] Registry stopped tracking node %s for service %s", id, s.Name)
|
||||
delete(m.nodes, nodeTrackId(s.Name, s.Version, id))
|
||||
go m.sendEvent(®istry.Result{Action: "delete", Service: s})
|
||||
}
|
||||
log.Debugf("[memory] Registry deleting service %s: no service nodes", s.Name)
|
||||
delete(m.Services, s.Name)
|
||||
return nil
|
||||
} else {
|
||||
// find out which nodes have been removed
|
||||
for _, id := range svcNodes[s.Name][s.Version] {
|
||||
for _, svc := range updatedService {
|
||||
var found bool
|
||||
for _, n := range svc.Nodes {
|
||||
if id == n.Id {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
log.Debugf("[memory] Registry stopped tracking node %s for service %s", id, s.Name)
|
||||
delete(m.nodes, nodeTrackId(s.Name, s.Version, id))
|
||||
go m.sendEvent(®istry.Result{Action: "delete", Service: s})
|
||||
}
|
||||
}
|
||||
m.Services[s.Name] = updatedService
|
||||
if len(m.records[s.Name][s.Version].Nodes) == 0 {
|
||||
delete(m.records[s.Name], s.Version)
|
||||
log.Debugf("Registry removed service: %s, version: %s", s.Name, s.Version)
|
||||
}
|
||||
}
|
||||
if len(m.records[s.Name]) == 0 {
|
||||
delete(m.records, s.Name)
|
||||
log.Debugf("Registry removed service: %s", s.Name)
|
||||
}
|
||||
go m.sendEvent(®istry.Result{Action: "delete", Service: s})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Registry) GetService(name string) ([]*registry.Service, error) {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
|
||||
records, ok := m.records[name]
|
||||
if !ok {
|
||||
return nil, registry.ErrNotFound
|
||||
}
|
||||
|
||||
services := make([]*registry.Service, len(m.records[name]))
|
||||
i := 0
|
||||
for _, record := range records {
|
||||
services[i] = recordToService(record)
|
||||
i++
|
||||
}
|
||||
|
||||
return services, nil
|
||||
}
|
||||
|
||||
func (m *Registry) ListServices() ([]*registry.Service, error) {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
|
||||
var services []*registry.Service
|
||||
for _, records := range m.records {
|
||||
for _, record := range records {
|
||||
services = append(services, recordToService(record))
|
||||
}
|
||||
}
|
||||
|
||||
return services, nil
|
||||
}
|
||||
|
||||
func (m *Registry) Watch(opts ...registry.WatchOption) (registry.Watcher, error) {
|
||||
var wo registry.WatchOptions
|
||||
for _, o := range opts {
|
||||
@@ -323,8 +274,9 @@ func (m *Registry) Watch(opts ...registry.WatchOption) (registry.Watcher, error)
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
m.Watchers[w.id] = w
|
||||
m.watchers[w.id] = w
|
||||
m.Unlock()
|
||||
|
||||
return w, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/registry"
|
||||
)
|
||||
@@ -102,10 +104,20 @@ func TestMemoryRegistry(t *testing.T) {
|
||||
|
||||
// register data
|
||||
for _, v := range testData {
|
||||
serviceCount := 0
|
||||
for _, service := range v {
|
||||
if err := m.Register(service); err != nil {
|
||||
t.Errorf("Unexpected register error: %v", err)
|
||||
}
|
||||
serviceCount++
|
||||
// after the service has been registered we should be able to query it
|
||||
services, err := m.GetService(service.Name)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting service %s: %v", service.Name, err)
|
||||
}
|
||||
if len(services) != serviceCount {
|
||||
t.Errorf("Expected %d services for %s, got %d", serviceCount, service.Name, len(services))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +126,22 @@ func TestMemoryRegistry(t *testing.T) {
|
||||
fn(k, v)
|
||||
}
|
||||
|
||||
services, err := m.ListServices()
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error when listing services: %v", err)
|
||||
}
|
||||
|
||||
totalServiceCount := 0
|
||||
for _, testSvc := range testData {
|
||||
for range testSvc {
|
||||
totalServiceCount++
|
||||
}
|
||||
}
|
||||
|
||||
if len(services) != totalServiceCount {
|
||||
t.Errorf("Expected total service count: %d, got: %d", totalServiceCount, len(services))
|
||||
}
|
||||
|
||||
// deregister
|
||||
for _, v := range testData {
|
||||
for _, service := range v {
|
||||
@@ -122,4 +150,94 @@ func TestMemoryRegistry(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// after all the service nodes have been deregistered we should not get any results
|
||||
for _, v := range testData {
|
||||
for _, service := range v {
|
||||
services, err := m.GetService(service.Name)
|
||||
if err != registry.ErrNotFound {
|
||||
t.Errorf("Expected error: %v, got: %v", registry.ErrNotFound, err)
|
||||
}
|
||||
if len(services) != 0 {
|
||||
t.Errorf("Expected %d services for %s, got %d", 0, service.Name, len(services))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemoryRegistryTTL(t *testing.T) {
|
||||
m := NewRegistry()
|
||||
|
||||
for _, v := range testData {
|
||||
for _, service := range v {
|
||||
if err := m.Register(service, registry.RegisterTTL(time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(ttlPruneTime * 2)
|
||||
|
||||
for name := range testData {
|
||||
svcs, err := m.GetService(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, svc := range svcs {
|
||||
if len(svc.Nodes) > 0 {
|
||||
t.Fatalf("Service %q still has nodes registered", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemoryRegistryTTLConcurrent(t *testing.T) {
|
||||
concurrency := 1000
|
||||
waitTime := ttlPruneTime * 2
|
||||
m := NewRegistry()
|
||||
|
||||
for _, v := range testData {
|
||||
for _, service := range v {
|
||||
if err := m.Register(service, registry.RegisterTTL(waitTime)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("test will wait %v, then check TTL timeouts", waitTime)
|
||||
|
||||
errChan := make(chan error, concurrency)
|
||||
syncChan := make(chan struct{})
|
||||
|
||||
for i := 0; i < concurrency; i++ {
|
||||
go func() {
|
||||
<-syncChan
|
||||
for name := range testData {
|
||||
svcs, err := m.GetService(name)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
|
||||
for _, svc := range svcs {
|
||||
if len(svc.Nodes) > 0 {
|
||||
errChan <- fmt.Errorf("Service %q still has nodes registered", name)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
errChan <- nil
|
||||
}()
|
||||
}
|
||||
|
||||
time.Sleep(waitTime)
|
||||
close(syncChan)
|
||||
|
||||
for i := 0; i < concurrency; i++ {
|
||||
if err := <-errChan; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,25 @@ import (
|
||||
|
||||
type servicesKey struct{}
|
||||
|
||||
func getServices(ctx context.Context) map[string][]*registry.Service {
|
||||
s, ok := ctx.Value(servicesKey{}).(map[string][]*registry.Service)
|
||||
func getServiceRecords(ctx context.Context) map[string]map[string]*record {
|
||||
memServices, ok := ctx.Value(servicesKey{}).(map[string][]*registry.Service)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return s
|
||||
|
||||
services := make(map[string]map[string]*record)
|
||||
|
||||
for name, svc := range memServices {
|
||||
if _, ok := services[name]; !ok {
|
||||
services[name] = make(map[string]*record)
|
||||
}
|
||||
// go through every version of the service
|
||||
for _, s := range svc {
|
||||
services[s.Name][s.Version] = serviceToRecord(s, 0)
|
||||
}
|
||||
}
|
||||
|
||||
return services
|
||||
}
|
||||
|
||||
// Services is an option that preloads service data
|
||||
|
||||
87
registry/memory/util.go
Normal file
87
registry/memory/util.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/registry"
|
||||
)
|
||||
|
||||
func serviceToRecord(s *registry.Service, ttl time.Duration) *record {
|
||||
metadata := make(map[string]string)
|
||||
for k, v := range s.Metadata {
|
||||
metadata[k] = v
|
||||
}
|
||||
|
||||
nodes := make(map[string]*node)
|
||||
for _, n := range s.Nodes {
|
||||
nodes[n.Id] = &node{
|
||||
Node: n,
|
||||
TTL: ttl,
|
||||
LastSeen: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
endpoints := make([]*registry.Endpoint, len(s.Endpoints))
|
||||
for i, e := range s.Endpoints {
|
||||
endpoints[i] = e
|
||||
}
|
||||
|
||||
return &record{
|
||||
Name: s.Name,
|
||||
Version: s.Version,
|
||||
Metadata: metadata,
|
||||
Nodes: nodes,
|
||||
Endpoints: endpoints,
|
||||
}
|
||||
}
|
||||
|
||||
func recordToService(r *record) *registry.Service {
|
||||
metadata := make(map[string]string)
|
||||
for k, v := range r.Metadata {
|
||||
metadata[k] = v
|
||||
}
|
||||
|
||||
endpoints := make([]*registry.Endpoint, len(r.Endpoints))
|
||||
for i, e := range r.Endpoints {
|
||||
request := new(registry.Value)
|
||||
request = e.Request
|
||||
response := new(registry.Value)
|
||||
response = e.Response
|
||||
|
||||
metadata := make(map[string]string)
|
||||
for k, v := range e.Metadata {
|
||||
metadata[k] = v
|
||||
}
|
||||
|
||||
endpoints[i] = ®istry.Endpoint{
|
||||
Name: e.Name,
|
||||
Request: request,
|
||||
Response: response,
|
||||
Metadata: metadata,
|
||||
}
|
||||
}
|
||||
|
||||
nodes := make([]*registry.Node, len(r.Nodes))
|
||||
i := 0
|
||||
for _, n := range r.Nodes {
|
||||
metadata := make(map[string]string)
|
||||
for k, v := range n.Metadata {
|
||||
metadata[k] = v
|
||||
}
|
||||
|
||||
nodes[i] = ®istry.Node{
|
||||
Id: n.Id,
|
||||
Address: n.Address,
|
||||
Metadata: metadata,
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
return ®istry.Service{
|
||||
Name: r.Name,
|
||||
Version: r.Version,
|
||||
Metadata: metadata,
|
||||
Endpoints: endpoints,
|
||||
Nodes: nodes,
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: micro/go-micro/registry/service/proto/registry.proto
|
||||
// source: go-micro/registry/service/proto/registry.proto
|
||||
|
||||
package go_micro_registry
|
||||
|
||||
import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
grpc "google.golang.org/grpc"
|
||||
math "math"
|
||||
)
|
||||
|
||||
@@ -48,7 +46,7 @@ func (x EventType) String() string {
|
||||
}
|
||||
|
||||
func (EventType) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{0}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{0}
|
||||
}
|
||||
|
||||
// Service represents a go-micro service
|
||||
@@ -68,7 +66,7 @@ func (m *Service) Reset() { *m = Service{} }
|
||||
func (m *Service) String() string { return proto.CompactTextString(m) }
|
||||
func (*Service) ProtoMessage() {}
|
||||
func (*Service) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{0}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{0}
|
||||
}
|
||||
|
||||
func (m *Service) XXX_Unmarshal(b []byte) error {
|
||||
@@ -146,7 +144,7 @@ func (m *Node) Reset() { *m = Node{} }
|
||||
func (m *Node) String() string { return proto.CompactTextString(m) }
|
||||
func (*Node) ProtoMessage() {}
|
||||
func (*Node) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{1}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{1}
|
||||
}
|
||||
|
||||
func (m *Node) XXX_Unmarshal(b []byte) error {
|
||||
@@ -210,7 +208,7 @@ func (m *Endpoint) Reset() { *m = Endpoint{} }
|
||||
func (m *Endpoint) String() string { return proto.CompactTextString(m) }
|
||||
func (*Endpoint) ProtoMessage() {}
|
||||
func (*Endpoint) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{2}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{2}
|
||||
}
|
||||
|
||||
func (m *Endpoint) XXX_Unmarshal(b []byte) error {
|
||||
@@ -273,7 +271,7 @@ func (m *Value) Reset() { *m = Value{} }
|
||||
func (m *Value) String() string { return proto.CompactTextString(m) }
|
||||
func (*Value) ProtoMessage() {}
|
||||
func (*Value) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{3}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{3}
|
||||
}
|
||||
|
||||
func (m *Value) XXX_Unmarshal(b []byte) error {
|
||||
@@ -327,7 +325,7 @@ func (m *Options) Reset() { *m = Options{} }
|
||||
func (m *Options) String() string { return proto.CompactTextString(m) }
|
||||
func (*Options) ProtoMessage() {}
|
||||
func (*Options) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{4}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{4}
|
||||
}
|
||||
|
||||
func (m *Options) XXX_Unmarshal(b []byte) error {
|
||||
@@ -369,7 +367,7 @@ func (m *Result) Reset() { *m = Result{} }
|
||||
func (m *Result) String() string { return proto.CompactTextString(m) }
|
||||
func (*Result) ProtoMessage() {}
|
||||
func (*Result) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{5}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{5}
|
||||
}
|
||||
|
||||
func (m *Result) XXX_Unmarshal(b []byte) error {
|
||||
@@ -421,7 +419,7 @@ func (m *EmptyResponse) Reset() { *m = EmptyResponse{} }
|
||||
func (m *EmptyResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*EmptyResponse) ProtoMessage() {}
|
||||
func (*EmptyResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{6}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{6}
|
||||
}
|
||||
|
||||
func (m *EmptyResponse) XXX_Unmarshal(b []byte) error {
|
||||
@@ -453,7 +451,7 @@ func (m *GetRequest) Reset() { *m = GetRequest{} }
|
||||
func (m *GetRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*GetRequest) ProtoMessage() {}
|
||||
func (*GetRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{7}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{7}
|
||||
}
|
||||
|
||||
func (m *GetRequest) XXX_Unmarshal(b []byte) error {
|
||||
@@ -492,7 +490,7 @@ func (m *GetResponse) Reset() { *m = GetResponse{} }
|
||||
func (m *GetResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*GetResponse) ProtoMessage() {}
|
||||
func (*GetResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{8}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{8}
|
||||
}
|
||||
|
||||
func (m *GetResponse) XXX_Unmarshal(b []byte) error {
|
||||
@@ -530,7 +528,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} }
|
||||
func (m *ListRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ListRequest) ProtoMessage() {}
|
||||
func (*ListRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{9}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{9}
|
||||
}
|
||||
|
||||
func (m *ListRequest) XXX_Unmarshal(b []byte) error {
|
||||
@@ -562,7 +560,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} }
|
||||
func (m *ListResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ListResponse) ProtoMessage() {}
|
||||
func (*ListResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{10}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{10}
|
||||
}
|
||||
|
||||
func (m *ListResponse) XXX_Unmarshal(b []byte) error {
|
||||
@@ -602,7 +600,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} }
|
||||
func (m *WatchRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*WatchRequest) ProtoMessage() {}
|
||||
func (*WatchRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{11}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{11}
|
||||
}
|
||||
|
||||
func (m *WatchRequest) XXX_Unmarshal(b []byte) error {
|
||||
@@ -649,7 +647,7 @@ func (m *Event) Reset() { *m = Event{} }
|
||||
func (m *Event) String() string { return proto.CompactTextString(m) }
|
||||
func (*Event) ProtoMessage() {}
|
||||
func (*Event) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2f73432195c6499a, []int{12}
|
||||
return fileDescriptor_0e39fd3e4b9b6e63, []int{12}
|
||||
}
|
||||
|
||||
func (m *Event) XXX_Unmarshal(b []byte) error {
|
||||
@@ -719,284 +717,52 @@ func init() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("micro/go-micro/registry/service/proto/registry.proto", fileDescriptor_2f73432195c6499a)
|
||||
proto.RegisterFile("go-micro/registry/service/proto/registry.proto", fileDescriptor_0e39fd3e4b9b6e63)
|
||||
}
|
||||
|
||||
var fileDescriptor_2f73432195c6499a = []byte{
|
||||
// 681 bytes of a gzipped FileDescriptorProto
|
||||
var fileDescriptor_0e39fd3e4b9b6e63 = []byte{
|
||||
// 679 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xdd, 0x6e, 0xd3, 0x4c,
|
||||
0x10, 0x8d, 0xed, 0xfc, 0x4e, 0xda, 0x7e, 0xfd, 0x46, 0x08, 0x8c, 0x5b, 0x20, 0xb2, 0x04, 0x0a,
|
||||
0x48, 0x4d, 0xaa, 0x50, 0x21, 0x7e, 0xae, 0x10, 0x0d, 0x95, 0x50, 0x0b, 0x62, 0xf9, 0xbb, 0x36,
|
||||
0x48, 0x75, 0xaa, 0x50, 0x21, 0x7e, 0xae, 0x10, 0x0d, 0x95, 0x50, 0x0b, 0x62, 0xf9, 0xbb, 0x36,
|
||||
0xf1, 0xa8, 0x58, 0x24, 0xb6, 0xd9, 0xdd, 0x46, 0xca, 0x3b, 0x20, 0xf1, 0x04, 0xbc, 0x0d, 0x4f,
|
||||
0xc1, 0xd3, 0xa0, 0x5d, 0xaf, 0x93, 0x54, 0xdd, 0x04, 0xa4, 0xc2, 0xdd, 0xcc, 0xee, 0x39, 0xb3,
|
||||
0xb3, 0x67, 0xce, 0xda, 0x70, 0x30, 0x49, 0x46, 0x3c, 0xeb, 0x9f, 0x66, 0x7b, 0x45, 0xc0, 0xe9,
|
||||
0x34, 0x11, 0x92, 0xcf, 0xfa, 0x82, 0xf8, 0x34, 0x19, 0x51, 0x3f, 0xe7, 0x99, 0x5c, 0x2c, 0xf7,
|
||||
0x74, 0x8a, 0xff, 0x9f, 0x66, 0x3d, 0x8d, 0xef, 0x95, 0x1b, 0xe1, 0x4f, 0x17, 0x1a, 0x6f, 0x0a,
|
||||
0x0e, 0x22, 0x54, 0xd3, 0x68, 0x42, 0xbe, 0xd3, 0x71, 0xba, 0x2d, 0xa6, 0x63, 0xf4, 0xa1, 0x31,
|
||||
0x25, 0x2e, 0x92, 0x2c, 0xf5, 0x5d, 0xbd, 0x5c, 0xa6, 0x78, 0x08, 0xcd, 0x09, 0xc9, 0x28, 0x8e,
|
||||
0x64, 0xe4, 0x7b, 0x1d, 0xaf, 0xdb, 0x1e, 0x74, 0x7b, 0x17, 0xea, 0xf7, 0x4c, 0xed, 0xde, 0x89,
|
||||
0x81, 0x0e, 0x53, 0xc9, 0x67, 0x6c, 0xce, 0xc4, 0x47, 0xd0, 0xa2, 0x34, 0xce, 0xb3, 0x24, 0x95,
|
||||
0xc2, 0xaf, 0xea, 0x32, 0x3b, 0x96, 0x32, 0x43, 0x83, 0x61, 0x0b, 0x34, 0xee, 0x41, 0x2d, 0xcd,
|
||||
0x62, 0x12, 0x7e, 0x4d, 0xd3, 0xae, 0x59, 0x68, 0x2f, 0xb3, 0x98, 0x58, 0x81, 0xc2, 0x03, 0x68,
|
||||
0x64, 0xb9, 0x4c, 0xb2, 0x54, 0xf8, 0xf5, 0x8e, 0xd3, 0x6d, 0x0f, 0x02, 0x0b, 0xe1, 0x55, 0x81,
|
||||
0x60, 0x25, 0x34, 0x78, 0x02, 0x9b, 0xe7, 0x5a, 0xc7, 0x6d, 0xf0, 0x3e, 0xd3, 0xcc, 0x68, 0xa4,
|
||||
0x42, 0xbc, 0x02, 0xb5, 0x69, 0x34, 0x3e, 0x23, 0x23, 0x50, 0x91, 0x3c, 0x76, 0x1f, 0x3a, 0xe1,
|
||||
0x0f, 0x07, 0xaa, 0xaa, 0x05, 0xdc, 0x02, 0x37, 0x89, 0x0d, 0xc7, 0x4d, 0x62, 0xa5, 0x6a, 0x14,
|
||||
0xc7, 0x9c, 0x84, 0x28, 0x55, 0x35, 0xa9, 0x9a, 0x41, 0x9e, 0x71, 0xe9, 0x7b, 0x1d, 0xa7, 0xeb,
|
||||
0x31, 0x1d, 0xe3, 0xd3, 0x25, 0xa5, 0x0b, 0x89, 0x6e, 0xaf, 0xb8, 0xeb, 0x2a, 0x99, 0x2f, 0x77,
|
||||
0x8d, 0xaf, 0x2e, 0x34, 0xcb, 0x01, 0x58, 0x4d, 0x32, 0x80, 0x06, 0xa7, 0x2f, 0x67, 0x24, 0xa4,
|
||||
0x26, 0xb7, 0x07, 0xbe, 0xa5, 0xbf, 0xf7, 0xaa, 0x1e, 0x2b, 0x81, 0x78, 0x00, 0x4d, 0x4e, 0x22,
|
||||
0xcf, 0x52, 0x41, 0xfa, 0xb2, 0xeb, 0x48, 0x73, 0x24, 0x0e, 0x2f, 0x48, 0x71, 0x77, 0x8d, 0x5b,
|
||||
0xfe, 0x8d, 0x1c, 0x11, 0xd4, 0x74, 0x5b, 0x56, 0x29, 0x10, 0xaa, 0x72, 0x96, 0x97, 0x2c, 0x1d,
|
||||
0xe3, 0x3e, 0xd4, 0x35, 0x5b, 0x98, 0x77, 0xb2, 0xfa, 0xa2, 0x06, 0x17, 0xee, 0x40, 0xc3, 0x38,
|
||||
0x51, 0x75, 0x26, 0xe5, 0x58, 0x9f, 0xe1, 0x31, 0x15, 0x86, 0x12, 0xea, 0x8c, 0xc4, 0xd9, 0x58,
|
||||
0xe2, 0x55, 0xa8, 0x47, 0x23, 0x05, 0x33, 0x2d, 0x98, 0x4c, 0x59, 0xdd, 0x7c, 0x07, 0xcc, 0x3c,
|
||||
0x82, 0xd5, 0x2f, 0x93, 0x95, 0x50, 0xdc, 0x85, 0x96, 0x4c, 0x26, 0x24, 0x64, 0x34, 0xc9, 0x8d,
|
||||
0xff, 0x16, 0x0b, 0xe1, 0x7f, 0xb0, 0x39, 0x9c, 0xe4, 0x72, 0xc6, 0xcc, 0x28, 0xc2, 0x3b, 0x00,
|
||||
0x47, 0x24, 0x99, 0x19, 0xa7, 0xbf, 0x38, 0xb2, 0xe8, 0xa5, 0x4c, 0xc3, 0x21, 0xb4, 0x35, 0xce,
|
||||
0x4c, 0xf0, 0x01, 0x34, 0xcd, 0x8e, 0xf0, 0x1d, 0x2d, 0xc7, 0xba, 0xe6, 0xe6, 0xd8, 0x70, 0x13,
|
||||
0xda, 0xc7, 0x89, 0x28, 0xcf, 0x0b, 0x9f, 0xc3, 0x46, 0x91, 0x5e, 0xb2, 0x6c, 0x17, 0x36, 0x3e,
|
||||
0x44, 0x72, 0xf4, 0xe9, 0xf7, 0xf7, 0xf8, 0xee, 0x40, 0x6d, 0x38, 0xa5, 0x54, 0x5e, 0x78, 0xcd,
|
||||
0xfb, 0x4b, 0x33, 0xdf, 0x1a, 0xec, 0xda, 0x0c, 0xa9, 0x78, 0x6f, 0x67, 0x39, 0x19, 0x47, 0xac,
|
||||
0x95, 0x7a, 0x79, 0x7c, 0xd5, 0x3f, 0x1e, 0xdf, 0xbd, 0x3e, 0xb4, 0xe6, 0xc7, 0x20, 0x40, 0xfd,
|
||||
0x19, 0xa7, 0x48, 0xd2, 0x76, 0x45, 0xc5, 0x87, 0x34, 0x26, 0x49, 0xdb, 0x8e, 0x8a, 0xdf, 0xe5,
|
||||
0xb1, 0x5a, 0x77, 0x07, 0xdf, 0x3c, 0x68, 0x32, 0x53, 0x0e, 0x4f, 0xf4, 0x34, 0xcb, 0x3f, 0xc1,
|
||||
0x0d, 0xcb, 0x81, 0x8b, 0x61, 0x07, 0x37, 0x57, 0x6d, 0x1b, 0x6b, 0x54, 0xf0, 0x45, 0x59, 0x9a,
|
||||
0x38, 0xae, 0xe9, 0x3e, 0xe8, 0xd8, 0xc4, 0x3a, 0x67, 0xb3, 0x0a, 0x1e, 0x03, 0x1c, 0x12, 0xff,
|
||||
0x5b, 0xd5, 0x5e, 0x17, 0xc6, 0x31, 0x14, 0x81, 0xb6, 0xbb, 0x2c, 0x19, 0x2d, 0xb8, 0xb5, 0x72,
|
||||
0x7f, 0x5e, 0xf2, 0x08, 0x6a, 0xda, 0x43, 0x68, 0xc3, 0x2e, 0xbb, 0x2b, 0xb8, 0x6e, 0x01, 0x14,
|
||||
0x6f, 0x39, 0xac, 0xec, 0x3b, 0x1f, 0xeb, 0xfa, 0x37, 0x7d, 0xff, 0x57, 0x00, 0x00, 0x00, 0xff,
|
||||
0xff, 0x69, 0x33, 0x08, 0xdb, 0xde, 0x07, 0x00, 0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion4
|
||||
|
||||
// RegistryClient is the client API for Registry service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
||||
type RegistryClient interface {
|
||||
GetService(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error)
|
||||
Register(ctx context.Context, in *Service, opts ...grpc.CallOption) (*EmptyResponse, error)
|
||||
Deregister(ctx context.Context, in *Service, opts ...grpc.CallOption) (*EmptyResponse, error)
|
||||
ListServices(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error)
|
||||
Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (Registry_WatchClient, error)
|
||||
}
|
||||
|
||||
type registryClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewRegistryClient(cc *grpc.ClientConn) RegistryClient {
|
||||
return ®istryClient{cc}
|
||||
}
|
||||
|
||||
func (c *registryClient) GetService(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) {
|
||||
out := new(GetResponse)
|
||||
err := c.cc.Invoke(ctx, "/go.micro.registry.Registry/GetService", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *registryClient) Register(ctx context.Context, in *Service, opts ...grpc.CallOption) (*EmptyResponse, error) {
|
||||
out := new(EmptyResponse)
|
||||
err := c.cc.Invoke(ctx, "/go.micro.registry.Registry/Register", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *registryClient) Deregister(ctx context.Context, in *Service, opts ...grpc.CallOption) (*EmptyResponse, error) {
|
||||
out := new(EmptyResponse)
|
||||
err := c.cc.Invoke(ctx, "/go.micro.registry.Registry/Deregister", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *registryClient) ListServices(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) {
|
||||
out := new(ListResponse)
|
||||
err := c.cc.Invoke(ctx, "/go.micro.registry.Registry/ListServices", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *registryClient) Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (Registry_WatchClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &_Registry_serviceDesc.Streams[0], "/go.micro.registry.Registry/Watch", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := ®istryWatchClient{stream}
|
||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := x.ClientStream.CloseSend(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Registry_WatchClient interface {
|
||||
Recv() (*Result, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type registryWatchClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *registryWatchClient) Recv() (*Result, error) {
|
||||
m := new(Result)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// RegistryServer is the server API for Registry service.
|
||||
type RegistryServer interface {
|
||||
GetService(context.Context, *GetRequest) (*GetResponse, error)
|
||||
Register(context.Context, *Service) (*EmptyResponse, error)
|
||||
Deregister(context.Context, *Service) (*EmptyResponse, error)
|
||||
ListServices(context.Context, *ListRequest) (*ListResponse, error)
|
||||
Watch(*WatchRequest, Registry_WatchServer) error
|
||||
}
|
||||
|
||||
func RegisterRegistryServer(s *grpc.Server, srv RegistryServer) {
|
||||
s.RegisterService(&_Registry_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _Registry_GetService_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RegistryServer).GetService(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/go.micro.registry.Registry/GetService",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RegistryServer).GetService(ctx, req.(*GetRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Registry_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Service)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RegistryServer).Register(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/go.micro.registry.Registry/Register",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RegistryServer).Register(ctx, req.(*Service))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Registry_Deregister_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Service)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RegistryServer).Deregister(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/go.micro.registry.Registry/Deregister",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RegistryServer).Deregister(ctx, req.(*Service))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Registry_ListServices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RegistryServer).ListServices(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/go.micro.registry.Registry/ListServices",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RegistryServer).ListServices(ctx, req.(*ListRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Registry_Watch_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
m := new(WatchRequest)
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return srv.(RegistryServer).Watch(m, ®istryWatchServer{stream})
|
||||
}
|
||||
|
||||
type Registry_WatchServer interface {
|
||||
Send(*Result) error
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type registryWatchServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *registryWatchServer) Send(m *Result) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
var _Registry_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "go.micro.registry.Registry",
|
||||
HandlerType: (*RegistryServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetService",
|
||||
Handler: _Registry_GetService_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Register",
|
||||
Handler: _Registry_Register_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Deregister",
|
||||
Handler: _Registry_Deregister_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListServices",
|
||||
Handler: _Registry_ListServices_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
StreamName: "Watch",
|
||||
Handler: _Registry_Watch_Handler,
|
||||
ServerStreams: true,
|
||||
},
|
||||
},
|
||||
Metadata: "micro/go-micro/registry/service/proto/registry.proto",
|
||||
0xc1, 0xd3, 0xa0, 0x5d, 0xaf, 0x93, 0x54, 0xb5, 0x03, 0x52, 0xe1, 0x6e, 0x66, 0xf7, 0x9c, 0xd9,
|
||||
0xd9, 0x33, 0x67, 0x6d, 0x08, 0x4e, 0xd3, 0xbd, 0x69, 0x3c, 0xe6, 0xe9, 0x80, 0xd3, 0x69, 0x2c,
|
||||
0x24, 0x9f, 0x0f, 0x04, 0xf1, 0x59, 0x3c, 0xa6, 0x41, 0xc6, 0x53, 0xb9, 0x5c, 0x0e, 0x74, 0x8a,
|
||||
0xff, 0x9f, 0xa6, 0x81, 0xc6, 0x07, 0xc5, 0x86, 0xff, 0xd3, 0x86, 0xd6, 0x9b, 0x9c, 0x83, 0x08,
|
||||
0xf5, 0x24, 0x9c, 0x92, 0x6b, 0xf5, 0xac, 0x7e, 0x87, 0xe9, 0x18, 0x5d, 0x68, 0xcd, 0x88, 0x8b,
|
||||
0x38, 0x4d, 0x5c, 0x5b, 0x2f, 0x17, 0x29, 0x1e, 0x42, 0x7b, 0x4a, 0x32, 0x8c, 0x42, 0x19, 0xba,
|
||||
0x4e, 0xcf, 0xe9, 0x77, 0x87, 0xfd, 0xe0, 0x42, 0xfd, 0xc0, 0xd4, 0x0e, 0x4e, 0x0c, 0x74, 0x94,
|
||||
0x48, 0x3e, 0x67, 0x0b, 0x26, 0x3e, 0x82, 0x0e, 0x25, 0x51, 0x96, 0xc6, 0x89, 0x14, 0x6e, 0x5d,
|
||||
0x97, 0xd9, 0x29, 0x29, 0x33, 0x32, 0x18, 0xb6, 0x44, 0xe3, 0x1e, 0x34, 0x92, 0x34, 0x22, 0xe1,
|
||||
0x36, 0x34, 0xed, 0x5a, 0x09, 0xed, 0x65, 0x1a, 0x11, 0xcb, 0x51, 0x78, 0x00, 0xad, 0x34, 0x93,
|
||||
0x71, 0x9a, 0x08, 0xb7, 0xd9, 0xb3, 0xfa, 0xdd, 0xa1, 0x57, 0x42, 0x78, 0x95, 0x23, 0x58, 0x01,
|
||||
0xf5, 0x9e, 0xc0, 0xe6, 0xb9, 0xd6, 0x71, 0x1b, 0x9c, 0xcf, 0x34, 0x37, 0x1a, 0xa9, 0x10, 0xaf,
|
||||
0x40, 0x63, 0x16, 0x4e, 0xce, 0xc8, 0x08, 0x94, 0x27, 0x8f, 0xed, 0x87, 0x96, 0xff, 0xc3, 0x82,
|
||||
0xba, 0x6a, 0x01, 0xb7, 0xc0, 0x8e, 0x23, 0xc3, 0xb1, 0xe3, 0x48, 0xa9, 0x1a, 0x46, 0x11, 0x27,
|
||||
0x21, 0x0a, 0x55, 0x4d, 0xaa, 0x66, 0x90, 0xa5, 0x5c, 0xba, 0x4e, 0xcf, 0xea, 0x3b, 0x4c, 0xc7,
|
||||
0xf8, 0x74, 0x45, 0xe9, 0x5c, 0xa2, 0xdb, 0x15, 0x77, 0xad, 0x92, 0xf9, 0x72, 0xd7, 0xf8, 0x6a,
|
||||
0x43, 0xbb, 0x18, 0x40, 0xa9, 0x49, 0x86, 0xd0, 0xe2, 0xf4, 0xe5, 0x8c, 0x84, 0xd4, 0xe4, 0xee,
|
||||
0xd0, 0x2d, 0xe9, 0xef, 0xbd, 0xaa, 0xc7, 0x0a, 0x20, 0x1e, 0x40, 0x9b, 0x93, 0xc8, 0xd2, 0x44,
|
||||
0x90, 0xbe, 0xec, 0x3a, 0xd2, 0x02, 0x89, 0xa3, 0x0b, 0x52, 0xdc, 0x5d, 0xe3, 0x96, 0x7f, 0x23,
|
||||
0x47, 0x08, 0x0d, 0xdd, 0x56, 0xa9, 0x14, 0x08, 0x75, 0x39, 0xcf, 0x0a, 0x96, 0x8e, 0x71, 0x1f,
|
||||
0x9a, 0x9a, 0x2d, 0xcc, 0x3b, 0xa9, 0xbe, 0xa8, 0xc1, 0xf9, 0x3b, 0xd0, 0x32, 0x4e, 0x54, 0x9d,
|
||||
0x49, 0x39, 0xd1, 0x67, 0x38, 0x4c, 0x85, 0xbe, 0x84, 0x26, 0x23, 0x71, 0x36, 0x91, 0x78, 0x15,
|
||||
0x9a, 0xe1, 0x58, 0xc1, 0x4c, 0x0b, 0x26, 0x53, 0x56, 0x37, 0xdf, 0x01, 0x33, 0x0f, 0xaf, 0xfa,
|
||||
0x65, 0xb2, 0x02, 0x8a, 0xbb, 0xd0, 0x91, 0xf1, 0x94, 0x84, 0x0c, 0xa7, 0x99, 0xf1, 0xdf, 0x72,
|
||||
0xc1, 0xff, 0x0f, 0x36, 0x47, 0xd3, 0x4c, 0xce, 0x99, 0x19, 0x85, 0x7f, 0x07, 0xe0, 0x88, 0x24,
|
||||
0x33, 0xe3, 0x74, 0x97, 0x47, 0xe6, 0xbd, 0x14, 0xa9, 0x3f, 0x82, 0xae, 0xc6, 0x99, 0x09, 0x3e,
|
||||
0x80, 0xb6, 0xd9, 0x11, 0xae, 0xa5, 0xe5, 0x58, 0xd7, 0xdc, 0x02, 0xeb, 0x6f, 0x42, 0xf7, 0x38,
|
||||
0x16, 0xc5, 0x79, 0xfe, 0x73, 0xd8, 0xc8, 0xd3, 0x4b, 0x96, 0xed, 0xc3, 0xc6, 0x87, 0x50, 0x8e,
|
||||
0x3f, 0xfd, 0xfe, 0x1e, 0xdf, 0x2d, 0x68, 0x8c, 0x66, 0x94, 0xc8, 0x0b, 0xaf, 0x79, 0x7f, 0x65,
|
||||
0xe6, 0x5b, 0xc3, 0xdd, 0x32, 0x43, 0x2a, 0xde, 0xdb, 0x79, 0x46, 0xc6, 0x11, 0x6b, 0xa5, 0x5e,
|
||||
0x1d, 0x5f, 0xfd, 0x8f, 0xc7, 0x77, 0x6f, 0x00, 0x9d, 0xc5, 0x31, 0x08, 0xd0, 0x7c, 0xc6, 0x29,
|
||||
0x94, 0xb4, 0x5d, 0x53, 0xf1, 0x21, 0x4d, 0x48, 0xd2, 0xb6, 0xa5, 0xe2, 0x77, 0x59, 0xa4, 0xd6,
|
||||
0xed, 0xe1, 0x37, 0x07, 0xda, 0xcc, 0x94, 0xc3, 0x13, 0x3d, 0xcd, 0xe2, 0x4f, 0x70, 0xa3, 0xe4,
|
||||
0xc0, 0xe5, 0xb0, 0xbd, 0x9b, 0x55, 0xdb, 0xc6, 0x1a, 0x35, 0x7c, 0x51, 0x94, 0x26, 0x8e, 0x6b,
|
||||
0xba, 0xf7, 0x7a, 0x65, 0x62, 0x9d, 0xb3, 0x59, 0x0d, 0x8f, 0x01, 0x0e, 0x89, 0xff, 0xad, 0x6a,
|
||||
0xaf, 0x73, 0xe3, 0x18, 0x8a, 0xc0, 0xb2, 0xbb, 0xac, 0x18, 0xcd, 0xbb, 0x55, 0xb9, 0xbf, 0x28,
|
||||
0x79, 0x04, 0x0d, 0xed, 0x21, 0x2c, 0xc3, 0xae, 0xba, 0xcb, 0xbb, 0x5e, 0x02, 0xc8, 0xdf, 0xb2,
|
||||
0x5f, 0xdb, 0xb7, 0x3e, 0x36, 0xf5, 0x6f, 0xfa, 0xfe, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4c,
|
||||
0x3e, 0x92, 0x97, 0xd8, 0x07, 0x00, 0x00,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user