qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [07/13] qpid-proton git commit: NO-JIRA: go: example error handling fix
Date Tue, 07 Feb 2017 20:52:17 GMT
NO-JIRA: go: example error handling fix

Examples were not reporting errors correctly.


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

Branch: refs/heads/go1
Commit: cf30fff21265f49809874363682f5d15848caad0
Parents: 6a23500
Author: Alan Conway <aconway@redhat.com>
Authored: Fri Jan 27 17:19:21 2017 -0500
Committer: Alan Conway <aconway@redhat.com>
Committed: Wed Feb 1 15:26:10 2017 -0500

----------------------------------------------------------------------
 examples/go/electron/receive.go | 42 +++++++++++++++++++-----------------
 examples/go/electron/send.go    | 36 ++++++++++++++++---------------
 2 files changed, 41 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/cf30fff2/examples/go/electron/receive.go
----------------------------------------------------------------------
diff --git a/examples/go/electron/receive.go b/examples/go/electron/receive.go
index 37a8583..e48d53c 100644
--- a/examples/go/electron/receive.go
+++ b/examples/go/electron/receive.go
@@ -70,28 +70,24 @@ func main() {
 		debugf("Connecting to %s\n", urlStr)
 		go func(urlStr string) { // Start the goroutine
 			defer wait.Done() // Notify main() when this goroutine is done.
-			var err error
-			if url, err := amqp.ParseURL(urlStr); err == nil {
-				if c, err := container.Dial("tcp", url.Host); err == nil {
-					connections <- c // Save connection so we can Close() when main() ends
-					if r, err := c.Receiver(electron.Source(url.Path)); err == nil {
-						// Loop receiving messages and sending them to the main() goroutine
-						for {
-							if rm, err := r.Receive(); err == nil {
-								rm.Accept()
-								messages <- rm.Message
-							} else if err == electron.Closed {
-								return
-							} else {
-								log.Fatal("receive error %v: %v", urlStr, err)
-							}
-						}
-					}
+			url, err := amqp.ParseURL(urlStr)
+			fatalIf(err)
+			c, err := container.Dial("tcp", url.Host)
+			fatalIf(err)
+			connections <- c // Save connection so we can Close() when main() ends
+			r, err := c.Receiver(electron.Source(url.Path))
+			fatalIf(err)
+			// Loop receiving messages and sending them to the main() goroutine
+			for {
+				if rm, err := r.Receive(); err == nil {
+					rm.Accept()
+					messages <- rm.Message
+				} else if err == electron.Closed {
+					return
+				} else {
+					log.Fatal("receive error %v: %v", urlStr, err)
 				}
 			}
-			if err != nil {
-				log.Fatal(err)
-			}
 		}(urlStr)
 	}
 
@@ -114,3 +110,9 @@ func main() {
 	}
 	wait.Wait() // Wait for all goroutines to finish.
 }
+
+func fatalIf(err error) {
+	if err != nil {
+		log.Fatal(err)
+	}
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/cf30fff2/examples/go/electron/send.go
----------------------------------------------------------------------
diff --git a/examples/go/electron/send.go b/examples/go/electron/send.go
index f478f4b..2338b23 100644
--- a/examples/go/electron/send.go
+++ b/examples/go/electron/send.go
@@ -69,23 +69,19 @@ func main() {
 		Debugf("Connecting to %v\n", urlStr)
 		go func(urlStr string) {
 			defer wait.Done() // Notify main() when this goroutine is done.
-			var err error
-			if url, err := amqp.ParseURL(urlStr); err == nil {
-				if c, err := container.Dial("tcp", url.Host); err == nil {
-					connections <- c // Save connection so we can Close() when main() ends
-					if s, err := c.Sender(electron.Target(url.Path)); err == nil {
-						// Loop sending messages.
-						for i := int64(0); i < *count; i++ {
-							m := amqp.NewMessage()
-							body := fmt.Sprintf("%v%v", url.Path, i)
-							m.Marshal(body)
-							s.SendAsync(m, sentChan, body) // Outcome will be sent to sentChan
-						}
-					}
-				}
-			}
-			if err != nil {
-				log.Fatal(err)
+			url, err := amqp.ParseURL(urlStr)
+			fatalIf(err)
+			c, err := container.Dial("tcp", url.Host)
+			fatalIf(err)
+			connections <- c // Save connection so we can Close() when main() ends
+			s, err := c.Sender(electron.Target(url.Path))
+			fatalIf(err)
+			// Loop sending messages.
+			for i := int64(0); i < *count; i++ {
+				m := amqp.NewMessage()
+				body := fmt.Sprintf("%v%v", url.Path, i)
+				m.Marshal(body)
+				s.SendAsync(m, sentChan, body) // Outcome will be sent to sentChan
 			}
 		}(urlStr)
 	}
@@ -111,3 +107,9 @@ func main() {
 		}
 	}
 }
+
+func fatalIf(err error) {
+	if err != nil {
+		log.Fatal(err)
+	}
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message