<commit_before>//Package negotiator is a library that handles content negotiation in web applications written in Go.
//
//For more information visit http://github.com/jchannon/negotiator
//
//	func getUser(w http.ResponseWriter, req *http.Request) {
//	    user := &User{"Joe","Bloggs"}
//	    negotiator.Negotiate(w, req, user)
//	}
//
package negotiator

import "net/http"

//Negotiator is responsible for content negotiation
type Negotiator struct{ processors []ResponseProcessor }

//New sets up response processors. By default XML and JSON are created
func New(responseProcessors ...ResponseProcessor) *Negotiator {
	processors := []ResponseProcessor{&jsonProcessor{}, &xmlProcessor{}}
	processors = append(responseProcessors, processors...)
	return &Negotiator{
		processors,
	}
}

//AddResponseProcessor allows you to add custom ResponseProcessors for your own content negotiation eg/PDF
// func (n *Negotiator) AddResponseProcessor(responseProcessors ...ResponseProcessor) {
// 	//ResponseProcessor is an interface and you shouldnt declare a pointer to an interface *ResponseProcessor
// 	n.processors = append(responseProcessors, n.processors...)
// }

//Negotiate your model based on HTTP Accept header
func (n *Negotiator) Negotiate(w http.ResponseWriter, req *http.Request, model interface{}) {
	negotiateHeader(n.processors, w, req, model)
}

//Negotiate your model based on HTTP Accept header
func Negotiate(w http.ResponseWriter, req *http.Request, model interface{}) {
	processors := []ResponseProcessor{&jsonProcessor{}, &xmlProcessor{}}
	negotiateHeader(processors, w, req, model)
}

func negotiateHeader(processors []ResponseProcessor, w http.ResponseWriter, req *http.Request, model interface{}) {
	accept := new(accept)

	accept.Header = req.Header.Get("Accept")

	for _, mr := range accept.ParseMediaRanges() {
		if len(mr.Value) == 0 {
			continue
		}
		for _, processor := range processors {
			if processor.CanProcess(mr.Value) {
				processor.Process(w, model)
				return
			}
		}
	}

	//rfc2616-sec14.1
	//If an Accept header field is present, and if the
	//server cannot send a response which is acceptable according to the combined
	//Accept field value, then the server SHOULD send a 406 (not acceptable)
	//response.
	http.Error(w, "", http.StatusNotAcceptable)
}
<commit_msg>removed commented code<commit_after>//Package negotiator is a library that handles content negotiation in web applications written in Go.
//
//For more information visit http://github.com/jchannon/negotiator
//
//	func getUser(w http.ResponseWriter, req *http.Request) {
//	    user := &User{"Joe","Bloggs"}
//	    negotiator.Negotiate(w, req, user)
//	}
//
package negotiator

import "net/http"

//Negotiator is responsible for content negotiation
type Negotiator struct{ processors []ResponseProcessor }

//New sets up response processors. By default XML and JSON are created
func New(responseProcessors ...ResponseProcessor) *Negotiator {
	processors := []ResponseProcessor{&jsonProcessor{}, &xmlProcessor{}}
	processors = append(responseProcessors, processors...)
	return &Negotiator{
		processors,
	}
}

//Negotiate your model based on HTTP Accept header
func (n *Negotiator) Negotiate(w http.ResponseWriter, req *http.Request, model interface{}) {
	negotiateHeader(n.processors, w, req, model)
}

//Negotiate your model based on HTTP Accept header
func Negotiate(w http.ResponseWriter, req *http.Request, model interface{}) {
	processors := []ResponseProcessor{&jsonProcessor{}, &xmlProcessor{}}
	negotiateHeader(processors, w, req, model)
}

func negotiateHeader(processors []ResponseProcessor, w http.ResponseWriter, req *http.Request, model interface{}) {
	accept := new(accept)

	accept.Header = req.Header.Get("Accept")

	for _, mr := range accept.ParseMediaRanges() {
		if len(mr.Value) == 0 {
			continue
		}
		for _, processor := range processors {
			if processor.CanProcess(mr.Value) {
				processor.Process(w, model)
				return
			}
		}
	}

	//rfc2616-sec14.1
	//If an Accept header field is present, and if the
	//server cannot send a response which is acceptable according to the combined
	//Accept field value, then the server SHOULD send a 406 (not acceptable)
	//response.
	http.Error(w, "", http.StatusNotAcceptable)
}

{'fraction_non_alphanumeric': 0.11555660155330666, 'fraction_numerical': 0.0051776888679689334, 'mean_word_length': 4.469755469755469, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2166279', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1221, 'n_words': 401}