<commit_before>package main

import (
  "fmt"
  "github.com/goji/zenazn/goji"
)

func main() {
  goji.Get("/", Root)
  goji.Post("/process_image", ProcessImage)
  goji.Serve()
}

func Root(w http.ResponseWriter, r *http.Request) {
  io.WriteString(w, "Hello, and welcome to Picasso!")
}

func ProcessImage(w http.ResponseWriter, r *http.Request) {
  
}
<commit_msg>Working on decoding images and validating them.<commit_after>package main

import (
  "fmt"
  "io"
  "net/http"
  "regexp"
  "strconv"
  "image"

  "github.com/zenazn/goji"
)

const (
  maxContentLength int = 5140000 // 5MB
)

func main() {
  goji.Get("/", Root)
  goji.Post("/process_image", ProcessImage)
  goji.Serve()
}

func Root(w http.ResponseWriter, r *http.Request) {
  io.WriteString(w, "Hello, and welcome to Picasso!")
}

func ProcessImage(w http.ResponseWriter, r *http.Request) {
  contentTypes := r.Header["Content-Type"]
  contentTypeRegex, _ := regexp.Compile("multipart/form-data")

  for _, contentType := range contentTypes {
    if !contentTypeRegex.MatchString(contentType) {
      message := fmt.Sprintf("Bad content type: `%s` is not currently not supported", contentType)
      http.Error(w, message, http.StatusBadRequest)
    }
  }

  contentLength, _ := strconv.Atoi(r.Header["Content-Length"][0])
  if contentLength > maxContentLength {
    message := fmt.Sprintf("Bad content length: `%d` exceeds the maximum file size", contentLength)
    http.Error(w, message, http.StatusBadRequest)
  }

  err := r.ParseMultipartForm(int64(maxContentLength))
  if err != nil {
    message := fmt.Sprintf("Error parsing multipart-form: %s", err.Error())
    http.Error(w, message, http.StatusBadRequest)
  }

  imgFiles, imgFileExists := r.MultipartForm.File["file"]
  if !imgFileExists {
    message := "Error parsing multipart-form: must specify a `file` field"
    http.Error(w, message, http.StatusBadRequest)
  }

  if len(imgFiles) > 1 {
    message := "Only expected a single file to be uploaded, not multiple"
    http.Error(w, message, http.StatusBadRequest)
  }

  multipartImgFile, err := imgFiles[0].Open()
  if err != nil {
    message := fmt.Sprintf("Error opening file: %s", err.Error())
    http.Error(w, message, http.StatusBadRequest)
  }

  img, imgFormat, err := image.DecodeConfig(multipartImgFile)
  if err != nil {
    message := fmt.Sprintf("Error decoding image file: %s", err.Error())
    http.Error(w, message, http.StatusBadRequest)
  }

  fmt.Println(img)
  fmt.Println(imgFormat)
}

{'fraction_non_alphanumeric': 0.14199759326113118, 'fraction_numerical': 0.005214600882470918, 'mean_word_length': 3.997995991983968, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1097093', 'n_tokens_mistral': 867, 'n_tokens_neox': 840, 'n_words': 197}