func HandleHookedRequest(r http.ResponseWriter, req *http.Request) {
	r.Header().Add("Content-Type", "application/json")
	if req.ContentLength < 1 {
		r.WriteHeader(http.StatusBadRequest)
		r.Write([]byte(fmt.Sprintf(`{"message": "no text passed. Cannot run sentiment analysis"}`)))
		log.Printf("POST /task > ERROR: no text passed\n")
		return
	}
	data, err := ioutil.ReadAll(req.Body)
	if err != nil && err != io.EOF {
		r.WriteHeader(http.StatusInternalServerError)
		r.Write([]byte(fmt.Sprintf(`{"message": "ERROR: error reading request body", "error": "%v"}`, err.Error())))
		log.Printf("POST /task > ERROR: error reading request\n\t%v\n", err)
		return
	}
	j := TaskJSON{}
	err = json.Unmarshal(data, &j)
	if err != nil {
		r.WriteHeader(http.StatusBadRequest)
		r.Write([]byte(fmt.Sprintf(`{"message": "ERROR: error unmarshalling given JSON into expected format", "error": "%v"}`, err.Error())))
		log.Printf("POST /task > ERROR: error unmarshalling given JSON\n\t%v\n", err)
		return
	}
	series, text, lang, err := GetHookResponse(j)
	if err != nil {
		r.WriteHeader(http.StatusInternalServerError)
		r.Write([]byte(fmt.Sprintf(`{"message": "ERROR: unable to get text from hook request with configured parameters", "error": %v}`, err)))
		log.Printf("POST /task > ERROR: error getting hooked response\n\t%v\n", err)
		return
	}
	resp := []byte{}
	analysis := model.SentimentAnalysis(text, lang)
	if series == nil {
		resp, err = json.Marshal(analysis)
	} else {
		for i := range series {
			series[i].Score = model.SentimentAnalysis(series[i].Text, lang).Score
		}
		resp, err = json.Marshal(TimeSeriesResponse{
			Metadata: analysis,
			Series:   series,
		})
	}
	if err != nil {
		r.WriteHeader(http.StatusInternalServerError)
		r.Write([]byte(fmt.Sprintf(`{"message": "ERROR: unable to marshal sentiment analysis into JSON", "error": "%v"}`, err.Error())))
		log.Printf("POST /task > ERROR: error marshalling sentiment analysis into JSON\n\t%v\n", err)
		return
	}
	r.WriteHeader(http.StatusOK)
	r.Write(resp)
	hookCount++
	count++
	log.Printf("POST /task [len(text) = %v]\n", len(text))
}
HandleHookedRequest is an http.HandlerFunc
which will take a POST request with some id
string and a hook_id string, post a GET request
to the hook number with the parameters provided
in the configuration, and run sentiment analysis
on the returned item (it's expected to have a 'text'
param in the JSON body)
package main
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
	"github.com/cdipaolo/sentiment"
)
var (
	client    *http.Client
	count     int64
	hookCount int64
)
func init() {
	client = &http.Client{}
	count = 0
	hookCount = 0
}
func HandleStatus(r http.ResponseWriter, req *http.Request) {
	if req.URL.Path != "/" {
		http.NotFound(r, req)
		return
	}
	r.Header().Add("Content-Type", "application/json")
	r.WriteHeader(http.StatusOK)
	r.Write([]byte(fmt.Sprintf(`{
		"status": "Up",
		"totalSuccessfulAnalyses": %v,
		"hookedRequests": %v
	}`, count, hookCount)))
	log.Printf("GET / [totalSuccessfulAnalyses = %v]\n", count)
}
func HandleSentiment(r http.ResponseWriter, req *http.Request) {
	r.Header().Add("Content-Type", "application/json")
	if req.ContentLength < 1 {
		r.WriteHeader(http.StatusBadRequest)
		r.Write([]byte(fmt.Sprintf(`{"message": "no text passed. Cannot run sentiment analysis"}`)))
		log.Printf("POST /analyze > ERROR: no text passed\n")
		return
	}
	data, err := ioutil.ReadAll(req.Body)
	if err != nil && err != io.EOF {
		r.WriteHeader(http.StatusInternalServerError)
		r.Write([]byte(fmt.Sprintf(`{"message": "ERROR: error reading request body", "error": "%v"}`, err.Error())))
		log.Printf("POST /analyze > ERROR: couldn't read request body\n\t%v\n", err)
		return
	}
	j := AnalyzeJSON{}
	err = json.Unmarshal(data, &j)
	if err != nil {
		r.WriteHeader(http.StatusBadRequest)
		r.Write([]byte(fmt.Sprintf(`{"message": "ERROR: error unmarshalling given JSON into expected format", "error": "%v"}`, err.Error())))
		log.Printf("POST /analyze > ERROR: error unmarshalling given JSON\n\t%v\n", err)
		return
	}
	analysis := model.SentimentAnalysis(j.Text, j.Language)
	resp, err := json.Marshal(analysis)
	if err != nil {
		r.WriteHeader(http.StatusInternalServerError)
		r.Write([]byte(fmt.Sprintf(`{"message": "ERROR: unable to marshal sentiment analysis into JSON", "error": "%v"}`, err.Error())))
		log.Printf("POST /analyze > ERROR: unable to unmarshal sentiment analysis into JSON\n\t%v\n", err)
		return
	}
	r.WriteHeader(http.StatusOK)
	r.Write(resp)
	count++
	log.Printf("POST /analyze [len(text) = %v]\n", len(j.Text))
}