<commit_before>package web

import (
	"encoding/json"
	"io"
	"net/http"

	"github.com/altairsix/pkg/types"

	"github.com/julienschmidt/httprouter"
)

type HandlerFunc func(c *Context) error

type Context struct {
	Request    *http.Request
	Response   http.ResponseWriter
	params     httprouter.Params
	data       map[string]interface{}
	formParsed bool
}

func (c *Context) RouteValue(name string) string {
	return c.params.ByName(name)
}

func (c *Context) RouteKey(name string) types.Key {
	return types.Key(c.RouteValue(name))
}

func (c *Context) RouteID(name string) types.ID {
	id, err := types.NewID(c.RouteValue(name))
	if err != nil {
		return types.ZeroID
	}

	return id
}

func (c *Context) Query(name string) string {
	if c.formParsed {
		c.Request.ParseForm()
	}

	return c.Request.FormValue(name)
}

func (c *Context) FormValue(name string) string {
	if c.formParsed {
		c.Request.ParseForm()
	}

	return c.Request.PostFormValue(name)
}

func (c *Context) Set(k string, v interface{}) {
	if c.data == nil {
		c.data = map[string]interface{}{}
	}
	c.data[k] = v
}

func (c *Context) Get(k string) interface{} {
	if c.data == nil {
		c.data = map[string]interface{}{}
	}

	return c.data[k]
}

func (c *Context) JSON(status int, in interface{}) error {
	c.Response.Header().Set("Content-Type", "application/json")
	c.Response.WriteHeader(status)
	return json.NewEncoder(c.Response).Encode(in)
}

func (c *Context) XMLBlob(status int, in []byte) error {
	c.Response.Header().Set("Content-Type", "text/xml")
	c.Response.WriteHeader(status)
	_, err := c.Response.Write(in)
	return err
}

func (c *Context) String(status int, in string) error {
	c.Response.Header().Set("Content-Type", "text/plain")
	c.Response.WriteHeader(status)
	_, err := io.WriteString(c.Response, in)
	return err
}

func (c *Context) HTML(status int, in string) error {
	c.Response.Header().Set("Content-Type", "text/html")
	c.Response.WriteHeader(status)
	_, err := io.WriteString(c.Response, in)
	return err<commit_msg>- renamed String to Text<commit_after>package web

import (
	"encoding/json"
	"io"
	"net/http"

	"github.com/altairsix/pkg/types"

	"github.com/julienschmidt/httprouter"
)

type HandlerFunc func(c *Context) error

type Context struct {
	Request    *http.Request
	Response   http.ResponseWriter
	params     httprouter.Params
	data       map[string]interface{}
	formParsed bool
}

func (c *Context) RouteValue(name string) string {
	return c.params.ByName(name)
}

func (c *Context) RouteKey(name string) types.Key {
	return types.Key(c.RouteValue(name))
}

func (c *Context) RouteID(name string) types.ID {
	id, err := types.NewID(c.RouteValue(name))
	if err != nil {
		return types.ZeroID
	}

	return id
}

func (c *Context) Query(name string) string {
	if c.formParsed {
		c.Request.ParseForm()
	}

	return c.Request.FormValue(name)
}

func (c *Context) FormValue(name string) string {
	if c.formParsed {
		c.Request.ParseForm()
	}

	return c.Request.PostFormValue(name)
}

func (c *Context) Set(k string, v interface{}) {
	if c.data == nil {
		c.data = map[string]interface{}{}
	}
	c.data[k] = v
}

func (c *Context) Get(k string) interface{} {
	if c.data == nil {
		c.data = map[string]interface{}{}
	}

	return c.data[k]
}

func (c *Context) JSON(status int, in interface{}) error {
	c.Response.Header().Set("Content-Type", "application/json")
	c.Response.WriteHeader(status)
	return json.NewEncoder(c.Response).Encode(in)
}

func (c *Context) XMLBlob(status int, in []byte) error {
	c.Response.Header().Set("Content-Type", "text/xml")
	c.Response.WriteHeader(status)
	_, err := c.Response.Write(in)
	return err
}

func (c *Context) Text(status int, in string) error {
	c.Response.Header().Set("Content-Type", "text/plain")
	c.Response.WriteHeader(status)
	_, err := io.WriteString(c.Response, in)
	return err
}

func (c *Context) HTML(status int, in string) error {
	c.Response.Header().Set("Content-Type", "text/html")
	c.Response.WriteHeader(status)
	_, err := io.WriteString(c.Response, in)
	return err
{'fraction_non_alphanumeric': 0.1543256045873847, 'fraction_numerical': 0.0, 'mean_word_length': 4.2928759894459105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7080040', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1465, 'n_words': 337}