<commit_before>package r2router

import (
	//"fmt"
	"net/http"
)

type Middleware func(w http.ResponseWriter, req *http.Request, params Params, next func())

type Seefor struct {
	Router
	middlewares []Middleware
}

func NewSeeforRouter() *Seefor {
	c4 := &Seefor{}
	c4.middlewares = make([]Middleware, 0)
	c4.roots = make(map[string]*rootNode)
	c4.HandleMethodNotAllowed = true
	return c4
}

func (c4 *Seefor) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	if root, exist := c4.roots[req.Method]; exist {
		handler, params := root.match(req.URL.Path)
		if handler != nil {
			c4.handleMiddlewares(handler, w, req, params)
			return
		}
	}
	c4.Router.handleMissing(w, req)
}

func (c4 *Seefor) handleMiddlewares(handler Handler, w http.ResponseWriter, req *http.Request, params Params) {
	var next func()
	max := len(c4.middlewares) - 1
	counter := -1
	next = func() {
		if counter >= max {
			handler(w, req, params)
			return
		}
		counter += 1
		c4.middlewares[counter](w, req, params, next)
	}
	next()
}<commit_msg>Check first if there is middleware<commit_after>package r2router

import (
	//"fmt"
	"net/http"
)

type Middleware func(w http.ResponseWriter, req *http.Request, params Params, next func())

type Seefor struct {
	Router
	middlewares []Middleware
}

func NewSeeforRouter() *Seefor {
	c4 := &Seefor{}
	c4.middlewares = make([]Middleware, 0)
	c4.roots = make(map[string]*rootNode)
	c4.HandleMethodNotAllowed = true
	return c4
}

func (c4 *Seefor) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	if root, exist := c4.roots[req.Method]; exist {
		handler, params := root.match(req.URL.Path)
		if handler != nil {
			if len(c4.middlewares) > 0 {
				c4.handleMiddlewares(handler, w, req, params)
			} else {
				handler(w, req, params)
			}
			return
		}
	}
	c4.Router.handleMissing(w, req)
}

func (c4 *Seefor) handleMiddlewares(handler Handler, w http.ResponseWriter, req *http.Request, params Params) {
	var next func()
	max := len(c4.middlewares) - 1
	counter := -1
	next = func() {
		if counter >= max {
			handler(w, req, params)
			return
		}
		counter += 1
		c4.middlewares[counter](w, req, params, next)
	}
	next()
}
{'fraction_non_alphanumeric': 0.14026939154667906, 'fraction_numerical': 0.01672085462145843, 'mean_word_length': 3.9976798143851506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6285082', 'n_tokens_mistral': 873, 'n_tokens_neox': 818, 'n_words': 202}