<commit_before>package air

import (
	"encoding/json"
	"encoding/xml"
	"errors"
	"mime"
	"reflect"
)

// binder is a binder that binds request based on the MIME types.
type binder struct{}

// theBinder is the singleton of the `binder`.
var theBinder = &binder{}

// bind binds the r into the v.
func (b *binder) bind(v interface{}, r *Request) error {
	if r.Method == "GET" {
		return b.bindParams(v, r.Params())
	} else if r.Body == nil {
		return errors.New("request body cannot be empty")
	}

	mt, _, err := mime.ParseMediaType(r.Header("content-type").Value())
	if err != nil {
		return err
	}

	switch mt {
	case "application/json":
		err = json.NewDecoder(r.Body).Decode(v)
	case "application/xml":
		err = xml.NewDecoder(r.Body).Decode(v)
	case "application/x-www-form-urlencoded", "multipart/form-data":
		err = b.bindParams(v, r.Params())
	default:
		return errors.New("unsupported media type")
	}

	if err != nil {
		return err
	}

	return nil
}

// bindParams binds the params into the v.
func (b *binder) bindParams(v interface{}, params []*RequestParam) error {
	typ := reflect.TypeOf(v).Elem()
	if typ.Kind() != reflect.Struct {
		return errors.New("binding element must be a struct")<commit_msg>add msgpack support<commit_after>package air

import (
	"encoding/json"
	"encoding/xml"
	"errors"
	"mime"
	"reflect"
	
	"github.com/vmihailenco/msgpack"
)

// binder is a binder that binds request based on the MIME types.
type binder struct{}

// theBinder is the singleton of the `binder`.
var theBinder = &binder{}

// bind binds the r into the v.
func (b *binder) bind(v interface{}, r *Request) error {
	if r.Method == "GET" {
		return b.bindParams(v, r.Params())
	} else if r.Body == nil {
		return errors.New("request body cannot be empty")
	}

	mt, _, err := mime.ParseMediaType(r.Header("content-type").Value())
	if err != nil {
		return err
	}

	switch mt {
	case "application/json":
		err = json.NewDecoder(r.Body).Decode(v)
	case "application/msgpack":
		err = msgpack.NewDecoder(r.Body).Decode(v)
	case "application/xml":
		err = xml.NewDecoder(r.Body).Decode(v)
	case "application/x-www-form-urlencoded", "multipart/form-data":
		err = b.bindParams(v, r.Params())
	default:
		return errors.New("unsupported media type")
	}

	if err != nil {
		return err
	}

	return nil
}

// bindParams binds the params into the v.
func (b *binder) bindParams(v interface{}, params []*RequestParam) error {
	typ := reflect.TypeOf(v).Elem()
	if typ.Kind() != reflect.Struct {
		return errors.New("binding element must be a struct")
{'fraction_non_alphanumeric': 0.14854215918045705, 'fraction_numerical': 0.0, 'mean_word_length': 3.826996197718631, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '1288121', 'n_tokens_mistral': 927, 'n_tokens_neox': 880, 'n_words': 262}