<commit_before>package main

import (
  "fmt"
  "encoding/json"
  "net/http"
  "menteslibres.net/gosexy/redis"
)

var client *redis.Client
var redisKey = "analytics"

func redisConnect(host string, port uint)(error) {
  var err error
  client = redis.New()
  err = client.Connect(host, port)
  return err
}

func jsHandler(w http.ResponseWriter, r *http.Request) {
  serializedRequest, serializeError := json.Marshal(r)

  if serializeError != nil {
    fmt.Printf("Error: %s", serializeError.Error())
    http.Error(w, serializeError.Error(), http.StatusInternalServerError)
  }

  client.LPush(redisKey, serializedRequest)
  return
}

func main() {
  redisConnect("localhost", 6379)
  http.HandleFunc("/analytics.js", jsHandler)
  http.ListenAndServe(":8080", nil)
  client.Quit()
}<commit_msg>Use text/template instead of trying to do things myself. Log errors from ListenAndServe<commit_after>package analytics

import (
  "text/template"
  "encoding/json"
  "net/http"
  "log"
  "menteslibres.net/gosexy/redis"
)

var client *redis.Client
var redisKey = "analytics"

func redisConnect(host string, port uint)(error) {
  var err error
  client = redis.New()
  err = client.Connect(host, port)
  return err
}

func redisStore(value string) {
  client.LPush(redisKey, value)
}

func jsHandler(w http.ResponseWriter, r *http.Request) {
  serializedRequest, serializeError := json.Marshal(r)

  if serializeError != nil {
    http.Error(w, serializeError.Error(), http.StatusInternalServerError)
    return
  }

  redisStore(string(serializedRequest))
  w.Header().Set("Content-Type", "application/javascript")
  w.WriteHeader(http.StatusCreated)

  t, _ := template.ParseFiles("templates/analytics.js")
  t.Execute(w, nil)
}

func main() {
  redisConnect("localhost", 6379)
  http.HandleFunc("/analytics.js", jsHandler)
  log.Fatal(http.ListenAndServe(":8080", nil))
  client.Quit()
}
{'fraction_non_alphanumeric': 0.1336870026525199, 'fraction_numerical': 0.008488063660477453, 'mean_word_length': 4.6467065868263475, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '446589', 'n_tokens_mistral': 666, 'n_tokens_neox': 649, 'n_words': 135}