<commit_before>package main

import (
  "encoding/json"
  "fmt"
  "github.com/gwwfps/lolconf-probe/display"
  "github.com/natefinch/npipe"
  "log"
  "net/http"
)

type handler func(http.ResponseWriter, *http.Request)
type inner func() (interface{}, error)

func wrapHandler(h inner) handler {
  return func(w http.ResponseWriter, r *http.Request) {
    result, handlerError := h()
    if handlerError != nil {
      writeError(w, handlerError)
      return
    }

    serialized, marshalError := json.Marshal(result)
    if marshalError != nil {
      writeError(w, marshalError)
      return
    }

    w.Header().Set("Content-Type", "application/json; charset=utf-8")
    fmt.Fprint(w, string(serialized))
  }
}

func writeError(w http.ResponseWriter, e error) {
  w.WriteHeader(http.StatusInternalServerError)
  fmt.Fprint(w, e.Error())
}

func main() {
  http.HandleFunc("/resolutions", wrapHandler(display.ListAvailableResolutions))
  l, e := npipe.Listen(`\\.\pipe\lolconf`)
  if e != nil {
    log.Fatal("Error listening on pipe: ", e)
  }
  serveError := http.Serve(l, nil)
  if serveError != nil {
    log.Fatal("Http serve error: ", serveError)
  }
}<commit_msg>Revert "switched to using npipe instead of socket"<commit_after>package main

import (
  "encoding/json"
  "fmt"
  "github.com/gwwfps/lolconf-probe/display"
  "log"
  "net/http"
)

type handler func(http.ResponseWriter, *http.Request)
type inner func() (interface{}, error)

func wrapHandler(h inner) handler {
  return func(w http.ResponseWriter, r *http.Request) {
    result, handlerError := h()
    if handlerError != nil {
      writeError(w, handlerError)
      return
    }

    serialized, marshalError := json.Marshal(result)
    if marshalError != nil {
      writeError(w, marshalError)
      return
    }

    w.Header().Set("Content-Type", "application/json; charset=utf-8")
    fmt.Fprint(w, string(serialized))
  }
}

func writeError(w http.ResponseWriter, e error) {
  w.WriteHeader(http.StatusInternalServerError)
  fmt.Fprint(w, e.Error())
}

func main() {
  http.HandleFunc("/resolutions", wrapHandler(display.ListAvailableResolutions))
  e := http.ListenAndServe("127.0.0.1:5532", nil)
  if e != nil {
    log.Fatal("ListenAndServe: ", e)
  }
}
{'fraction_non_alphanumeric': 0.14355992844364937, 'fraction_numerical': 0.005366726296958855, 'mean_word_length': 3.6995798319327733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '687553', 'n_tokens_mistral': 777, 'n_tokens_neox': 765, 'n_words': 159}