<commit_before>package render

import (
	"encoding/json"
	"fmt"
	"net/http"
)

// Options type to configure rendering
type Options struct {
	Status int
	Data   interface{}
	Cache  bool
}

// Renders JSON and send it to the HTTP client, supports caching
func JSON(w http.ResponseWriter, opts Options) error {
	if &w == nil {
		return fmt.Errorf("You must provide a http.ResponseWriter")
	}

	headers := w.Header()
	headers.Set("Content-Type", "application/json; charset=utf-8")

	if opts.Cache {
		headers.Set("Cache-Control", "no-cache, no-store, must-revalidate")
		headers.Set("Pragma", "no-cache")
		headers.Set("Expires", "0")
	}

	jsonbytes, err := json.Marshal(opts.Data)
	if err != nil {
		return err
	}

	headers.Set("Content-Length", fmt.Sprintf("%d", len(jsonbytes)))
	if opts.Status <= 0 {
		opts.Status = http.StatusOK
	}
	w.WriteHeader(opts.Status)

	_, err = w.Write(jsonbytes)
	if err != nil {
		return err
	}

	return nil
}<commit_msg>Cleans up code to make it look more idiomatic.<commit_after>package render

import (
	"encoding/json"
	"fmt"
	"net/http"
	"strconv"
)

// Options type to configure rendering
type Options struct {
	Status int
	Data   interface{}
	Cache  bool
}

// Renders JSON and send it to the HTTP client, supports caching
func JSON(w http.ResponseWriter, opts Options) error {
	if &w == nil {
		return fmt.Errorf("You must provide a http.ResponseWriter")
	}

	headers := w.Header()
	headers.Set("Content-Type", "application/json; charset=utf-8")

	if opts.Cache {
		headers.Set("Cache-Control", "no-cache, no-store, must-revalidate")
		headers.Set("Pragma", "no-cache")
		headers.Set("Expires", "0")
	}

	jsonBytes, err := json.Marshal(opts.Data)
	if err != nil {
		return err
	}

	headers.Set("Content-Length", strconv.Itoa(len(jsonBytes)))
	if opts.Status <= 0 {
		opts.Status = http.StatusOK
	}
	w.WriteHeader(opts.Status)
	w.Write(jsonBytes)

	return nil
}
{'fraction_non_alphanumeric': 0.142781875658588, 'fraction_numerical': 0.003161222339304531, 'mean_word_length': 3.9069767441860463, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3058382', 'n_tokens_mistral': 686, 'n_tokens_neox': 653, 'n_words': 176}