From b3ba0e00464dd74b083e83a2d706d30bbc7155fe Mon Sep 17 00:00:00 2001
From: Matthew Treinish <mtreinish@kortar.org>
Date: Tue, 9 May 2017 16:21:16 -0400
Subject: [PATCH] Add a golang firehose example

This commit adds a firehose example for go to the firehose docs.

Change-Id: I29c1abd9c152fc8fb196b2a4e1734c6642d266dc
---
 doc/source/firehose.rst | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/doc/source/firehose.rst b/doc/source/firehose.rst
index 888085babd..247c712847 100644
--- a/doc/source/firehose.rst
+++ b/doc/source/firehose.rst
@@ -196,6 +196,43 @@ This requires the `mqtt-hs`_ library to be installed.
     terminated <- MQTT.run conf
     print terminated
 
+Go
+''
+.. code-block:: go
+    package main
+    import (
+      "fmt"
+      MQTT "github.com/eclipse/paho.mqtt.golang"
+      "os"
+      "strconv"
+      "time"
+    )
+    func onMessageReceived(client MQTT.Client, msg MQTT.Message) {
+        fmt.Printf("TOPIC: %s\n", msg.Topic())
+        fmt.Printf("MSG: %s\n", msg.Payload())
+    }
+    func main() {
+        hostname, _ := os.Hostname()
+        opts := &MQTT.ClientOptions{
+            ClientID: hostname+strconv.Itoa(time.Now().Second()),
+        }
+        opts.AddBroker("tcp://firehose.openstack.org:1883")
+        opts.OnConnect = func(c MQTT.Client) {
+            if token := c.Subscribe("#", 0, onMessageReceived); token.Wait() && token.Error() != nil {
+                fmt.Println(token.Error())
+                os.Exit(1)
+            }
+        }
+        client := MQTT.NewClient(opts)
+        if token := client.Connect(); token.Wait() && token.Error() != nil {
+            panic(token.Error())
+        }
+        for {
+            time.Sleep(1 * time.Second)
+        }
+    }
+
+
 Websocket Example
 -----------------
 In addition to using the raw MQTT protocol firehose.o.o  provides a websocket