<commit_before>package handlerutils

import (
	"io"
	"net/http"
	"os"

	"github.com/prasannavl/mchain"
)

func Nop(w http.ResponseWriter, r *http.Request) error {
	return nil
}

func NopHandler() mchain.Handler {
	return mchain.HandlerFunc(Nop)
}

func SendFileHandler(filePath string, status int) mchain.Handler {
	f := func(w http.ResponseWriter, r *http.Request) error {
		f, err := os.Open(filePath)
		if err != nil {
			return err
		}
		defer f.Close()
		return SendFromReader(w, f, status)
	}
	return mchain.HandlerFunc(f)
}

func SendStatusHandler(status int) mchain.Handler {
	f := func(w http.ResponseWriter, r *http.Request) error {
		w.WriteHeader(status)
		return nil
	}
	return mchain.HandlerFunc(f)
}

func SendFromReader(w http.ResponseWriter, reader io.Reader, status int) error {
	w.WriteHeader(status)
	_, err := io.Copy(w, reader)
	return err
}

func SendFromReaderHandler(reader io.Reader, status int) mchain.Handler {
	if reader == nil {
		return SendStatusHandler(status)
	}
	f := func(w http.ResponseWriter, r *http.Request) error {
		return SendFromReader(w, reader, status)
	}
	return mchain.HandlerFunc(f)
}<commit_msg>add: function helper handlers<commit_after>package handlerutils

import (
	"io"
	"net/http"
	"os"

	"github.com/prasannavl/mchain"
)

func Nop(w http.ResponseWriter, r *http.Request) error {
	return nil
}

func NopHandler() mchain.Handler {
	return mchain.HandlerFunc(Nop)
}

func SendFileHandler(filePath string, status int) mchain.Handler {
	f := func(w http.ResponseWriter, r *http.Request) error {
		f, err := os.Open(filePath)
		if err != nil {
			return err
		}
		defer f.Close()
		return SendFromReader(w, f, status)
	}
	return mchain.HandlerFunc(f)
}

func SendStatusHandler(status int) mchain.Handler {
	f := func(w http.ResponseWriter, r *http.Request) error {
		w.WriteHeader(status)
		return nil
	}
	return mchain.HandlerFunc(f)
}

func SendFromReader(w http.ResponseWriter, reader io.Reader, status int) error {
	w.WriteHeader(status)
	_, err := io.Copy(w, reader)
	return err
}

func SendFromReaderHandler(reader io.Reader, status int) mchain.Handler {
	if reader == nil {
		return SendStatusHandler(status)
	}
	f := func(w http.ResponseWriter, r *http.Request) error {
		return SendFromReader(w, reader, status)
	}
	return mchain.HandlerFunc(f)
}

func InvokeFunctionHandler(fn func()) mchain.Handler {
	f := func(w http.ResponseWriter, r *http.Request) error {
		fn()
		return nil
	}
	return mchain.HandlerFunc(f)
}

func FunctionResultHandler(fn func() error) mchain.Handler {
	f := func(w http.ResponseWriter, r *http.Request) error {
		return fn()
	}
	return mchain.HandlerFunc(f)
}

func InvokeFunctionStatusHandler(fn func(), status int) mchain.Handler {
	f := func(w http.ResponseWriter, r *http.Request) error {
		w.WriteHeader(status)
		fn()
		return nil
	}
	return mchain.HandlerFunc(f)
}

func FunctionResultStatusHandler(fn func() error, status int) mchain.Handler {
	f := func(w http.ResponseWriter, r *http.Request) error {
		w.WriteHeader(status)
		return fn()
	}
	return mchain.HandlerFunc(f)
}
{'fraction_non_alphanumeric': 0.12149837133550488, 'fraction_numerical': 0.0, 'mean_word_length': 4.523381294964029, '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': '890784', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1081, 'n_words': 269}