From 161a6826538945851cb367b1f743461265542839 Mon Sep 17 00:00:00 2001 From: chenshijun <csj_sky@126.com> Date: 星期三, 04 九月 2019 16:27:40 +0800 Subject: [PATCH] 合并晓龙因业务而增加的更新 --- searcher.go | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/searcher.go b/searcher.go index afd2daa..2f7096e 100644 --- a/searcher.go +++ b/searcher.go @@ -9,7 +9,7 @@ ) var ( - members [][]byte + members = make(map[string]NodeInfo,0) delay time.Duration ) @@ -53,7 +53,12 @@ // NotifyMsg is called when a user-data message is received func (d *delegate) NotifyMsg(b []byte) { // logMsg(b) - members = append(members, b) + n := NodeInfo{} + if err:= json.Unmarshal(b, &n);err ==nil { + members[n.NodeID] = n + } else { + fmt.Println("NotifyMsg msg unmarshal err") + } } func logMsg(b []byte) { @@ -90,7 +95,7 @@ return memberlist.Create(conf) } -func CreateSearchNodeWhitClose(key string, delay time.Duration) [][]byte { +func CreateSearchNodeWhitClose(key string, delay time.Duration) map[string]NodeInfo { m, err := CreateSearchNode(key) if err == nil { // fmt.Printf("Local member %s:%d\n", m.LocalNode().Addr, m.LocalNode().Port) @@ -105,6 +110,6 @@ return m.Shutdown() } -func GetSearchNodes() [][]byte { +func GetSearchNodes() map[string]NodeInfo { return members } -- Gitblit v1.8.0