From a4ea6380ed70468b1bbaca0328a65686960fcd52 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期一, 20 四月 2020 16:23:30 +0800 Subject: [PATCH] add svLock --- server.go | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/server.go b/server.go index 035f825..f23728c 100644 --- a/server.go +++ b/server.go @@ -3,6 +3,7 @@ import ( "encoding/json" "log" + "sync" "time" "golang.org/x/net/context" @@ -52,6 +53,7 @@ publisher *Publisher svInfo map[string][]byte + svLock sync.RWMutex } type Publisher struct { @@ -162,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() } } } @@ -244,6 +248,8 @@ } 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 -- Gitblit v1.8.0