Repository: qpid-proton
Updated Branches:
  refs/heads/go [created] dbd66666c


PROTON-827: go binding: minor example cleanup.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/dbd66666
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/dbd66666
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/dbd66666

Branch: refs/heads/go
Commit: dbd66666c45a8afb1350e0017972056c3f64a46d
Parents: 460c787
Author: Alan Conway <[email protected]>
Authored: Mon May 11 17:34:13 2015 -0400
Committer: Alan Conway <[email protected]>
Committed: Tue May 12 18:52:32 2015 -0400

----------------------------------------------------------------------
 examples/go/receive.go |  8 +++-----
 examples/go/send.go    | 34 ++++++++++++++++------------------
 2 files changed, 19 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/dbd66666/examples/go/receive.go
----------------------------------------------------------------------
diff --git a/examples/go/receive.go b/examples/go/receive.go
index fc1c85a..2545eab 100644
--- a/examples/go/receive.go
+++ b/examples/go/receive.go
@@ -92,16 +92,14 @@ Receive messages from all the listed URLs concurrently and 
print them.
                        url, err := proton.ParseURL(urlStr) // Like 
net/url.Parse() but with AMQP defaults.
                        fatalIf(err)
 
-                       // Open a standard Go net.Conn for the AMQP connection
+                       // Open a standard Go net.Conn and and AMQP connection 
using it.
                        conn, err := net.Dial("tcp", url.Host) // Note 
net.URL.Host is actually "host:port"
                        fatalIf(err)
-
                        pc, err := messaging.Connect(conn) // This is our AMQP 
connection.
                        fatalIf(err)
-                       connections[i] = pc
+                       connections[i] = pc // So we can close it when main() 
ends
 
-                       // For convenience a proton.Connection provides a 
DefaultSession()
-                       // pc.Receiver() is equivalent to 
pc.DefaultSession().Receiver()
+                       // Create a receiver using the path of the URL as the 
AMQP address
                        r, err := pc.Receiver(url.Path)
                        fatalIf(err)
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/dbd66666/examples/go/send.go
----------------------------------------------------------------------
diff --git a/examples/go/send.go b/examples/go/send.go
index 46603bf..c4db7cd 100644
--- a/examples/go/send.go
+++ b/examples/go/send.go
@@ -76,29 +76,27 @@ To each URL, send the string "path-n" where n is the 
message number.
        connections := make([]*messaging.Connection, len(urls))
        defer func() {
                for _, c := range connections {
-                       c.Close()
+                       if c != nil {
+                               c.Close()
+                       }
                }
        }()
 
        for i, urlStr := range urls {
-               url, err := proton.ParseURL(urlStr) // Like net/url.Parse() but 
with AMQP defaults.
-               fatalIf(err)
-               debug.Printf("Connecting to %v", url)
-
-               // Open a standard Go net.Conn for the AMQP connection
-               conn, err := net.Dial("tcp", url.Host) // Note net.URL.Host is 
actually "host:port"
-               fatalIf(err)
-
-               pc, err := messaging.Connect(conn) // This is our AMQP 
connection using conn.
-               fatalIf(err)
-               connections[i] = pc
-
-               // Start a goroutine to send to urlStr
+               debug.Printf("Connecting to %v", urlStr)
                go func(urlStr string) {
-                       defer wait.Done() // Notify main() that this goroutine 
is done.
+                       defer wait.Done()                   // Notify main() 
that this goroutine is done.
+                       url, err := proton.ParseURL(urlStr) // Like 
net/url.Parse() but with AMQP defaults.
+                       fatalIf(err)
+
+                       // Open a standard Go net.Conn and and AMQP connection 
using it.
+                       conn, err := net.Dial("tcp", url.Host) // Note 
net.URL.Host is actually "host:port"
+                       fatalIf(err)
+                       pc, err := messaging.Connect(conn) // This is our AMQP 
connection.
+                       fatalIf(err)
+                       connections[i] = pc // So we can close it when main() 
ends
 
-                       // FIXME aconway 2015-04-29: sessions, default 
sessions, senders...
-                       // Create a sender using the path of the URL as the 
AMQP target address
+                       // Create a sender using the path of the URL as the 
AMQP address
                        s, err := pc.Sender(url.Path)
                        fatalIf(err)
 
@@ -108,7 +106,7 @@ To each URL, send the string "path-n" where n is the 
message number.
                                m.SetBody(body)
                                ack, err := s.Send(m)
                                fatalIf(err)
-                               acks <- Ack{ack, body}
+                               acks <- Ack{ack, body} // Send the 
acknowledgement to main()
                        }
                }(urlStr)
        }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to