liuxiaolong
2020-04-20 a4ea6380ed70468b1bbaca0328a65686960fcd52
server.go
@@ -3,6 +3,7 @@
import (
   "encoding/json"
   "log"
   "sync"
   "time"
   "golang.org/x/net/context"
@@ -51,7 +52,8 @@
   // publisher, we are going to publish the changes of the set here
   publisher *Publisher
   svInfo map[string]interface{}
   svInfo map[string][]byte
   svLock sync.RWMutex
}
type Publisher struct {
@@ -150,6 +152,7 @@
   }
   responses = NewStringSet()
   d.services.svInfo = make(map[string][]byte, 0)
   for {
      msg, err = d.sock.Recv()
      if err != nil {
@@ -161,7 +164,9 @@
      } else {
         if  json.Unmarshal(msg, &si) == nil {
            responses.Add(si.ServiceId)
            d.services.svLock.Lock()
            d.services.svInfo[si.ServiceId] = si.Info
            d.services.svLock.Unlock()
         }
      }
   }
@@ -218,7 +223,7 @@
   s := &Services{
      nodes:     NewStringSet(),
      publisher: publisher,
      svInfo: make(map[string]interface{}, 0),
      svInfo: make(map[string][]byte, 0),
   }
   return s
@@ -242,8 +247,10 @@
   return d.services.nodes
}
func (d *DiscoveryServer) SvInfo() map[string]interface{} {
   m := make(map[string]interface{})
func (d *DiscoveryServer) SvInfo() map[string][]byte {
   d.services.svLock.Lock()
   defer d.services.svLock.Unlock()
   m := make(map[string][]byte)
   for k,v := range d.services.svInfo {
      m[k] = v
   }