<commit_before>package respond

import (
	"log"
	"net/http"
)

// With specifies the status code and data to repsond with.
func With(status int, data interface{}) *W {
	return &W{Code: status, Data: data}
}

// W holds details about the response that will be made
// when To is called.
type W struct {
	Code   int
	Data   interface{}
	header http.Header
}

// To writes the repsonse.
func (with *W) To(w http.ResponseWriter, r *http.Request) {
	// copy headers
	copyheaders(with.header, w.Header())
	// find the encoder
	encoder, ok := Encoders().Match(r.Header.Get("Accept"))
	if !ok {
		encoder = DefaultEncoder
	}
	// write response
	if err := Write(w, r, with.Code, with.Data, encoder); err != nil {
		Err(w, r, with, err)
	}
}

// Write is the function that sets the Content-Type, writes the header
// and encodes the body using the specified Encoder.
var Write = func(w http.ResponseWriter, r *http.Request, status int, data interface{}, encoder Encoder) error {
	w.Header().Set("Content-Type", encoder.ContentType(w, r))
	w.WriteHeader(status)
	return encoder.Encode(w, r, data)
}

// Err is called when an internal error occurs while responding.
var Err = func(w http.ResponseWriter, r *http.Request, with *W, err error) {
	log.Println("Err:", r.URL.String(), err)
}<commit_msg>tweak<commit_after>package respond

import (
	"log"
	"net/http"
)

// With specifies the status code and data to repsond with.
func With(status int, data interface{}) *W {
	return &W{Code: status, Data: data}
}

// W holds details about the response that will be made
// when To is called.
type W struct {
	Code   int
	Data   interface{}
	header http.Header
}

// To writes the repsonse.
func (with *W) To(w http.ResponseWriter, r *http.Request) {
	// copy headers to ResponseWriter
	copyheaders(with.header, w.Header())
	// find the encoder
	var encoder Encoder
	var ok bool
	if encoder, ok = Encoders().Match(r.Header.Get("Accept")); !ok {
		encoder = DefaultEncoder
	}
	// write response
	if err := Write(w, r, with.Code, with.Data, encoder); err != nil {
		Err(w, r, with, err)
	}
}

// Write is the function that sets the Content-Type, writes the header
// and encodes the body using the specified Encoder.
var Write = func(w http.ResponseWriter, r *http.Request, status int, data interface{}, encoder Encoder) error {
	w.Header().Set("Content-Type", encoder.ContentType(w, r))
	w.WriteHeader(status)
	return encoder.Encode(w, r, data)
}

// Err is called when an internal error occurs while responding.
var Err = func(w http.ResponseWriter, r *http.Request, with *W, err error) {
	log.Println("Err:", r.URL.String(), err)
}
{'fraction_non_alphanumeric': 0.1315487571701721, 'fraction_numerical': 0.0, 'mean_word_length': 3.8265682656826567, 'pattern_counts': {'":': 0, '<': 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': '3758871', 'n_tokens_mistral': 870, 'n_tokens_neox': 844, 'n_words': 312}