Perform Sentiment Analysis and Classification on Text in Go

Sometimes our own biases & preconceived notions make it difficult to aptly judge content. Thank goodness there’s an API for that: you can find out if input text is positive, negative or neutral with the Sentiment Analysis & Classification iteration of our Natural Language Processing API. Use code examples below to integrate this API into your Go project, or head to the Cloudmersive API Console to find code in 13 different programming languages for your convenience.

Copy in the following if you’re working in Go, and include your API key (easily attainable by making a free account on www.cloudmersive.com) and text string where indicated:

import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/nlp-v2/analytics/sentiment"
method := "POST"
payload := strings.NewReader("TextToAnalyze=%3Cstring%3E")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

--

--

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.