From 9893edc6dda92601c81b249967384f6626abc272 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期五, 17 五月 2019 09:49:21 +0800
Subject: [PATCH] add mangos bus interface to impl

---
 nng.go |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/nng.go b/nng.go
index 07f2fb5..eed0e59 100644
--- a/nng.go
+++ b/nng.go
@@ -20,6 +20,15 @@
 	"nanomsg.org/go-mangos/transport/all"
 )
 
+// type deliver
+type td int
+
+const (
+	producer = td(iota)
+	consumer
+	star //mangos bus protocol
+)
+
 // NNG mangos wrap
 type NNG struct {
 	sock   mangos.Socket
@@ -34,7 +43,7 @@
 func (n *NNG) Send(data []byte) error {
 	var err error
 	if n.sock == nil {
-		n.sock, err = n.makeNNG(true)
+		n.sock, err = n.makeNNG(producer)
 		if err != nil {
 			fmt.Println("create nng producer error")
 			return err
@@ -56,7 +65,7 @@
 	var err error
 
 	if n.sock == nil {
-		n.sock, err = n.makeNNG(false)
+		n.sock, err = n.makeNNG(consumer)
 		if err != nil {
 			fmt.Println("create nng consumer error")
 			return nil, err
@@ -102,18 +111,20 @@
 
 }
 
-func proto(producer bool, m Mode) protocol {
-	if producer {
+func proto(typ td, m Mode) protocol {
+	if typ == producer {
 		return protoProducer(m)
+	} else if typ == consumer {
+		return protoConsumer(m)
 	}
 	return protoConsumer(m)
 }
 
-func (n *NNG) makeNNG(producer bool) (mangos.Socket, error) {
+func (n *NNG) makeNNG(typ td) (mangos.Socket, error) {
 
 	var sock mangos.Socket
 	var err error
-	if sock, err = newSocket(proto(producer, n.mode)); err != nil {
+	if sock, err = newSocket(proto(typ, n.mode)); err != nil {
 		return nil, err
 	}
 

--
Gitblit v1.8.0