<commit_before>package kwiscale

import (
	"fmt"
	"log"
	"net/http"
	"reflect"
	"regexp"
)

type RouteMap struct {
	Route   *regexp.Regexp
	Handler IRequestHandler
}

// handlers stack
var globalhandlers []RouteMap

// sessions handler
var sessions map[string]map[string]interface{}

// add an hancler to the stack
func AddHandler(r IRequestHandler) {
	field, _ := reflect.TypeOf(r).Elem().FieldByName("RequestHandler")
	route := field.Tag.Get("route")
	log.Printf("Append route: %s", route)
	reg := regexp.MustCompile(route)
	routemap := RouteMap{reg, r}
	globalhandlers = append(globalhandlers, routemap)
}

// start to serve on given address:port
func Serve(address string) {
	http.Handle("/statics/", http.StripPrefix("/statics", http.FileServer(http.Dir("./statics"))))
	http.HandleFunc("/", dispatch)
	http.ListenAndServe(address, nil)
}

// dispatch request to correct handler
func dispatch(w http.ResponseWriter, r *http.Request) {

	defer func() {
		if err := recover(); err != nil {
			log.Println("ERROR", err)
			w.WriteHeader(http.StatusInternalServerError)
			fmt.Fprintf(w, "%v", err)
		}
	}()
<commit_msg>Append a configuration struct + AddHandler vararg<commit_after>package kwiscale

import (
	"fmt"
	"log"
	"net/http"
	"reflect"
	"regexp"
)

type Config struct {
    // static dir
    Statics string

    // template dir
    Templates string

    // Session cookie name 
    SessID  string
}

type RouteMap struct {
	Route   *regexp.Regexp
	Handler IRequestHandler
}

// handlers stack
var globalhandlers []RouteMap
var config Config

// sessions handler
var sessions map[string]map[string]interface{}

// GetConfig returns a pointer to the server configuration
func GetConfig() *Config {
    if config.Statics == "" {
        config = Config{
            Statics     : "./statics",
            Templates   : "./templates",
            SessID      : "SESSID",
        }

    }
    return &config
}

// add an hancler to the stack
func AddHandler(requests...  IRequestHandler) {
    for _, r := range requests {
        field, _ := reflect.TypeOf(r).Elem().FieldByName("RequestHandler")
        route := field.Tag.Get("route")
        log.Printf("Append route: %s", route)
        reg := regexp.MustCompile(route)
        routemap := RouteMap{reg, r}
        globalhandlers = append(globalhandlers, routemap)
    }
}

// start to serve on given address:port
func Serve(address string) {
	http.Handle("/statics/", http.StripPrefix("/statics", http.FileServer(http.Dir("./statics"))))
	http.HandleFunc("/", dispatch)
	http.ListenAndServe(address, nil)
}

// dispatch request to correct handler
func dispatch(w http.ResponseWriter, r *http.Request) {

	defer func() {
		if err := recover(); err != nil {
			log.Println("ERROR", err)
			w.WriteHeader(http.StatusInternalServerError)
			fmt.Fprintf(w, "%v", err)
		}
	}()

{'fraction_non_alphanumeric': 0.13580246913580246, 'fraction_numerical': 0.0, 'mean_word_length': 3.4802527646129544, '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': '5338010', 'n_tokens_mistral': 935, 'n_tokens_neox': 909, 'n_words': 229}