From a7f35d9126fa7803284038f8e69a22199cd35e64 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期二, 29 十二月 2020 10:48:06 +0800 Subject: [PATCH] 调整包结构 --- micronode.go | 33 ++++++++++++++++----------------- 1 files changed, 16 insertions(+), 17 deletions(-) diff --git a/mc/micronode.go b/micronode.go similarity index 84% rename from mc/micronode.go rename to micronode.go index 95d28cf..eafe20b 100644 --- a/mc/micronode.go +++ b/micronode.go @@ -2,7 +2,6 @@ import ( "basic.com/valib/bhomebus.git" - "bhomeclient" "context" "encoding/json" "errors" @@ -13,19 +12,19 @@ type MicroNode struct { ctx context.Context - handle *bhomeclient.BHBus - reg *bhomeclient.RegisterInfo - procInfo *bhomeclient.ProcInfo + handle *BHBus + reg *RegisterInfo + procInfo *ProcInfo handlers map[string]MicroFunc serverId string fnLog func(...interface{}) - SubChM map[string]chan *bhomeclient.MsgInfo //浠ヨ闃呯殑涓婚涓簁ey + SubChM map[string]chan *MsgInfo //浠ヨ闃呯殑涓婚涓簁ey } -func NewMicroNode(ctx context.Context,q chan os.Signal, serverId string, reg *bhomeclient.RegisterInfo, procInfo *bhomeclient.ProcInfo,fnLog func(v ...interface{})) (*MicroNode, error){ - conf := bhomeclient.NewConfig(bhomeclient.KEY_REGISTER,512,5,10,10,100, fnLog) - handle, err := bhomeclient.Register(ctx, q, conf, reg) +func NewMicroNode(ctx context.Context,q chan os.Signal, serverId string, reg *RegisterInfo, procInfo *ProcInfo,fnLog func(v ...interface{})) (*MicroNode, error){ + conf := NewConfig(KEY_REGISTER,512,5,10,10,100, fnLog) + handle, err := Register(ctx, q, conf, reg) if err != nil { return nil, err } @@ -35,10 +34,10 @@ reg: reg, procInfo: procInfo, fnLog: fnLog, - SubChM: make(map[string]chan *bhomeclient.MsgInfo), + SubChM: make(map[string]chan *MsgInfo), } for _,subTopic := range reg.SubTopic { - mn.SubChM[subTopic] = make(chan *bhomeclient.MsgInfo, 512) + mn.SubChM[subTopic] = make(chan *MsgInfo, 512) } return mn, nil @@ -52,7 +51,7 @@ } } -func (ms *MicroNode) UpdateNodeTopics(ts []bhomeclient.NodeInfo) { +func (ms *MicroNode) UpdateNodeTopics(ts []NodeInfo) { ms.handle.UpdateNodeTopics(ts) } @@ -64,7 +63,7 @@ } func (ms *MicroNode) startHeartbeat() { - hbi := &bhomeclient.HeartBeatInfo{ + hbi := &HeartBeatInfo{ HealthLevel: "health", Fps: 12, WarnInfo: "warn", @@ -125,7 +124,7 @@ ms.printLog("1:", time.Since(t)) t = time.Now() rb, _ := json.Marshal(request) - msgR := &bhomeclient.MsgInfo { + msgR := &MsgInfo { Topic: request.Path, Body: rb, } @@ -153,7 +152,7 @@ func (ms *MicroNode) RequestTopic(serverId string, request Request) (*Reply,error) { rb, _ := json.Marshal(request) - msgR := &bhomeclient.MsgInfo{ + msgR := &MsgInfo{ Topic: request.Path, Body: rb, } @@ -192,7 +191,7 @@ return netNodes } -func (ms *MicroNode) serve(msgR *bhomeclient.MsgInfo, p int) { +func (ms *MicroNode) serve(msgR *MsgInfo, p int) { var reqBody Request err := json.Unmarshal(msgR.Body, &reqBody) if err != nil { @@ -216,7 +215,7 @@ if err != nil { ms.printLog("marshal *ri err:", err) } - rMsg := bhomeclient.MsgInfo{ + rMsg := MsgInfo{ Body: rd, } ms.handle.Reply(p, rMsg) @@ -229,7 +228,7 @@ } func (ms *MicroNode) PublishNet(nodes []bhomebus.NetNode, topic string,msg []byte) error { - pi := &bhomeclient.MsgInfo{ + pi := &MsgInfo{ Topic: topic, Body: msg, } -- Gitblit v1.8.0