<commit_before>package main

import (
	"bufio"
	"net/http"

	"github.com/kataras/iris"
)

var (
	errStaticDataNotFound = "File: %s was not found"
)

func IrisAPI() *iris.Framework {

	api := iris.New()

	// TODO Gzip
	// iris.Config.Gzip = true

	// define the api
	api.Post("/api/schemas/:id", func(ctx *iris.Context) {

		id := ctx.Param("id")
		println("POST /api/schemas/" + id)

		// defaults
		jSONSchema := JSONSchema{
			Template:   "csv",
			EmptyValue: "",
			Count:      10,
		}

		parser := ValidatingJSONRequestParser{}
		template, err := parser.parse(ctx, &jSONSchema, id)
		if err != nil {
			emmitError(http.StatusBadRequest, err.Error(), ctx)
			return
		}

		// TODO slice to chunks + in separate go routines
		context := Context{
			FromIndex:    0,
			ToIndex:      jSONSchema.Count,
			CurrentIndex: []int{0},
		}
		ctx.SetContentType(template.ContentType(&context))
		ctx.StreamWriter(func(writer *bufio.Writer) {
			// TODO Gzip
			// ctx.Response.WriteGzip()

			out, err := template.Generate(&context)
			if err != nil {
				emmitError(http.StatusInternalServerError, err.Error(), ctx)
				return
			}

			// ? TODO http://stackoverflow.com/questions/25171385/how-should-i-add-buffering-to-a-gzip-writer
			writer.WriteString(out)

			writer.Flush()
		})

	})

	return api
}

func main() {
	IrisAPI().Listen(":9292")
}

func emmitError(errorCode int, errorString string, ctx *iris.Context) {
	ctx.EmitError(errorCode)
	ctx.Write(": " + errorString)
}
<commit_msg>fix: using argumentless template.ContentType()<commit_after>package main

import (
	"bufio"
	"net/http"

	"github.com/kataras/iris"
)

var (
	errStaticDataNotFound = "File: %s was not found"
)

func IrisAPI() *iris.Framework {

	api := iris.New()

	// TODO Gzip
	// iris.Config.Gzip = true

	// define the api
	api.Post("/api/schemas/:id", func(ctx *iris.Context) {

		id := ctx.Param("id")
		println("POST /api/schemas/" + id)

		// defaults
		jSONSchema := JSONSchema{
			Template:   "csv",
			EmptyValue: "",
			Count:      10,
		}

		parser := ValidatingJSONRequestParser{}
		template, err := parser.parse(ctx, &jSONSchema, id)
		if err != nil {
			emmitError(http.StatusBadRequest, err.Error(), ctx)
			return
		}

		// TODO slice to chunks + in separate go routines
		context := Context{
			FromIndex:    0,
			ToIndex:      jSONSchema.Count,
			CurrentIndex: []int{0},
		}
		ctx.SetContentType(template.ContentType())
		ctx.StreamWriter(func(writer *bufio.Writer) {
			// TODO Gzip
			// ctx.Response.WriteGzip()

			out, err := template.Generate(&context)
			if err != nil {
				emmitError(http.StatusInternalServerError, err.Error(), ctx)
				return
			}

			// ? TODO http://stackoverflow.com/questions/25171385/how-should-i-add-buffering-to-a-gzip-writer
			writer.WriteString(out)

			writer.Flush()
		})

	})

	return api
}

func main() {
	IrisAPI().Listen(":9292")
}

func emmitError(errorCode int, errorString string, ctx *iris.Context) {
	ctx.EmitError(errorCode)
	ctx.Write(": " + errorString)
}

{'fraction_non_alphanumeric': 0.15361546151282907, 'fraction_numerical': 0.010663112295901367, 'mean_word_length': 3.2581560283687945, 'pattern_counts': {'":': 4, '<': 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': '595303', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1073, 'n_words': 215}