Plantronics Developer Connection - go https://developer.plantronics.com/blog/go en Integrate Plantronics REST API from Go https://developer.plantronics.com/article/integrate-plantronics-rest-api-go <div class="field field-name-field-keywords field-type-taxonomy-term-reference field-label-above"> <div class="field-label">Keywords:&nbsp;</div> <div class="field-items"> <span class="field-item even label label-default keyword-label"><a href="/blog/go" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">go</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/sdk" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">SDK</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/api" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">API</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/rest" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">REST</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/plantronics" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">plantronics</a></span> </div> </div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded">Greetings!<br /> <br /> I have recently created an example integrate from the Go language to the Plantronics REST API.<br /> <br /> It is still a work in progress but it is functional for receiving device, session and session manager events. (For further guidance on the REST Service API URLs you can use, check out the Java and JavaScript integration samples elsewhere on this site).<br /> <br /> Obtain Go language (golang) from here: <a href="https://golang.org/">https://golang.org/</a><br /> <br /> Obtain the sample code from here: <a href="/system/files/plt%20go%20sample.zip">http://developer.plantronics.com/system/files/plt%20go%20sample.zip</a><br /> <strong>Note: </strong>you must login to this site to download that file.<br /> <br /> Here is how you connect to Plantronics from Go (code snippet):<br />   <pre class="prettyprint"> func httpGetJSON(url string) (map[string]interface{}) {     var dat map[string]interface{}     resp, err := http.Get(url)     if err != nil {         log.Fatal(err)     }     defer resp.Body.Close()     if b, err2 := ioutil.ReadAll(resp.Body); err2 == nil {         if err := json.Unmarshal(b, &amp;dat); err != nil {             log.Fatal(err)         }     }     return dat } func connectToPlantronics() { fmt.Print("Connecting to Plantronics...\r\n") var jsondata map[string]interface{} = httpGetJSON("http://127.0.0.1:32017/Spokes/DeviceServices/Attach?uid=0123456789") fmt.Print("\r\nSession ID:\r\n\r\n"+jsondata["Result"].(string)+"\r\n\r\n") sessionId = jsondata["Result"].(string) var result string = httpGet("http://127.0.0.1:32017/Spokes/SessionManager/Register?name="+pluginName) fmt.Print("\r\nResult:\r\n\r\n"+result+"\r\n\r\n") pluginRegistered = true go eventsListenerThread(sessionId,pluginName) // start monitoring events after connect to api } </pre> <br /> Below is a picture of the code in action, having received a "Don" event (when I put on the Plantronics headset)...<br /> Have fun!<br /> Lewis.<br /> <br /> <div class="media media-element-container media-default"><div id="file-111" class="file file-image file-image-png"> <h2 class="element-invisible"><a href="/files/go-samplepng">go sample.png</a></h2> <div class="content"> <img height="798" width="915" class="media-element file-default img-responsive" typeof="foaf:Image" src="https://developer.plantronics.com/sites/default/files/go%20sample.png" alt="" /> </div> </div> </div></div></div></div> Thu, 01 Sep 2016 12:06:32 +0000 lcollins 384 at https://developer.plantronics.com https://developer.plantronics.com/article/integrate-plantronics-rest-api-go#comments