From 8c3d1360e1102bc05545fb9bcf06355276d46dd8 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 21 一月 2020 16:05:26 +0800
Subject: [PATCH] dispatch functions

---
 app/master/daemon.go |   44 +++++++++++++++++++++++++-------------------
 1 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/app/master/daemon.go b/app/master/daemon.go
index 84d626b..8e849b8 100644
--- a/app/master/daemon.go
+++ b/app/master/daemon.go
@@ -12,6 +12,22 @@
 	"analysis/util"
 )
 
+const (
+	opRemove = "remove"
+	opAdd    = "add"
+)
+
+// Notice transit to slave
+type Notice struct {
+	Op      string   `json:"Op"`
+	Content []string `json:"Content"`
+}
+
+type transit struct {
+	chNotify chan<- []byte
+	cancel   context.CancelFunc
+}
+
 // NamedProc 鍗曚釜杩涚▼鍚嶅瓧鍜屾湇鍔¢�氶亾
 type NamedProc struct {
 	// 杩涚▼鍚嶅瓧
@@ -32,16 +48,6 @@
 	Typ string
 	// 鍏峰悕杩涚▼
 	SNameProc []NamedProc
-}
-
-// Notice transit to slave
-type Notice struct {
-	Op      string   `json:"Op"`
-	Content []string `json:"Content"`
-}
-type transit struct {
-	chNotify chan<- []byte
-	cancel   context.CancelFunc
 }
 
 // Worker 鍗曚釜杩涚▼鏈嶅姟
@@ -228,31 +234,31 @@
 				for _, w := range workers {
 					if v == w.info.Name {
 						// 鎵惧埌浜嗗搴斿悕瀛楃殑杩涚▼,棣栧厛姹備笉闇�瑕佸啀杩愯鐨勯�氶亾
-						var notice *Notice
 						removes := difference(w.info.Channels, proc.Channels)
 						if len(removes) > 0 {
 							// 閫氱煡瀛愯繘绋嬪叧闂�氶亾
-							notice = &Notice{
-								Op:      "remove",
+							notice = Notice{
+								Op:      opRemove,
 								Content: removes,
 							}
-
+							if d, err := json.Marshal(notice); err == nil {
+								w.trans.chNotify <- d
+							}
 						}
 
 						// 鍏舵姹傚嚭鏂板鐨勯�氶亾
 						adds := difference(proc.Channels, w.info.Channels)
 						if len(adds) > 0 {
 							// 閫氱煡瀛愯繘绋嬫墦寮�閫氶亾
-							notice = &Notice{
-								Op:      "add",
+							notice = Notice{
+								Op:      opAdd,
 								Content: adds,
 							}
-						}
-						if notice != nil {
-							if d, err := json.Marshal(*notice); err == nil {
+							if d, err := json.Marshal(notice); err == nil {
 								w.trans.chNotify <- d
 							}
 						}
+
 					}
 				}
 			}

--
Gitblit v1.8.0