<commit_before>package httpmux

import (
	"fmt"
	"net/http"

	errors "github.com/gogolfing/httpmux/errors"
	muxpath "github.com/gogolfing/httpmux/path"
)

type Route struct {
	path         string
	pathType     muxpath.PathType
	children     []*Route
	routeHandler *routeHandler
}

func newRoute(path string, children ...*Route) *Route {
	return &Route{
		path,
		muxpath.TypeOf(path),
		children,
		nil,
	}
}

func (route *Route) Delete(handler http.Handler) *Route {
	return route.Handle(handler, "DELETE")
}

func (route *Route) DeleteFunc(handlerFunc http.HandlerFunc) *Route {
	return route.HandleFunc(handlerFunc, "DELETE")
}

func (route *Route) Get(handler http.Handler) *Route {
	return route.Handle(handler, "GET")
}

func (route *Route) GetFunc(handlerFunc http.HandlerFunc) *Route {
	return route.HandleFunc(handlerFunc, "GET")
}

func (route *Route) Post(handler http.Handler) *Route {
	return route.Handle(handler, "POST")
}

func (route *Route) PostFunc(handlerFunc http.HandlerFunc) *Route {
	return route.HandleFunc(handlerFunc, "POST")
}

func (route *Route) Put(handler http.Handler) *Route {
	return route.Handle(handler, "PUT")
}

func (route *Route) PutFunc(handlerFunc http.HandlerFunc) *Route {
	return route.HandleFunc(handlerFunc, "PUT")
}

func (route *Route) SubRoute(path string) *Route {
	result, err := route.insertSubRoute(path)
	if err != nil {
		panic(err)
	}
	return result
}

func (route *Route) HandleFunc(handlerFunc http.HandlerFunc, methods ...string) *Route {
	return route.Handle(http.HandlerFunc(handlerFunc), methods...)
}

func (route *Route) Handle(handler http.Handler, methods ...string) *Route {
	if route.routeHandler == nil {
		route.routeHandler = &routeHandler{}
	}
	route.routeHandler.handle(handler, methods...)
	return route
}

func (route *Route) getHandler(r *http.Request) (http.Handler, error) {
	if route.routeHandler == nil {
		return nil, errors.ErrNotFound
	}
	return route.routeHandler.getHandler(r)
}

func (route *Route) ListRoutes() []string {
	result := []string{}
	methodsRoutes := route.listMethodsRoutes()
	for _, v := range methodsRoutes {
		result = append(result, v[0]+" "+v[1])
	}
	return result
}

func (route *Route) listMethodsRoutes() [][]string {
	result := [][]string{}
	if route.routeHandler != nil {
		methodsAll := route.routeHandler.methodsAll()
		for _, v := range methodsAll {
			result = append(result, []string{v, route.path})
		}
	}
	for _, child := range route.children {
		methodsRoutes := child.listMethodsRoutes()
		for _, v := range methodsRoutes {
			result = append(result, []string{v[0], route.path + v[1]})
		}
	}
	return result
}

func (route *Route) search(path string) (*Route, *Route, string) {
	return route.findStaticSubRoute(path)
}

func (route *Route) insertSubRoute(path string) (*Route, error) {
	if len(path) == 0 {<commit_msg>Changes location of *Route.getHandler().<commit_after>package httpmux

import (
	"fmt"
	"net/http"

	errors "github.com/gogolfing/httpmux/errors"
	muxpath "github.com/gogolfing/httpmux/path"
)

type Route struct {
	path         string
	pathType     muxpath.PathType
	children     []*Route
	routeHandler *routeHandler
}

func newRoute(path string, children ...*Route) *Route {
	return &Route{
		path,
		muxpath.TypeOf(path),
		children,
		nil,
	}
}

func (route *Route) Delete(handler http.Handler) *Route {
	return route.Handle(handler, "DELETE")
}

func (route *Route) DeleteFunc(handlerFunc http.HandlerFunc) *Route {
	return route.HandleFunc(handlerFunc, "DELETE")
}

func (route *Route) Get(handler http.Handler) *Route {
	return route.Handle(handler, "GET")
}

func (route *Route) GetFunc(handlerFunc http.HandlerFunc) *Route {
	return route.HandleFunc(handlerFunc, "GET")
}

func (route *Route) Post(handler http.Handler) *Route {
	return route.Handle(handler, "POST")
}

func (route *Route) PostFunc(handlerFunc http.HandlerFunc) *Route {
	return route.HandleFunc(handlerFunc, "POST")
}

func (route *Route) Put(handler http.Handler) *Route {
	return route.Handle(handler, "PUT")
}

func (route *Route) PutFunc(handlerFunc http.HandlerFunc) *Route {
	return route.HandleFunc(handlerFunc, "PUT")
}

func (route *Route) SubRoute(path string) *Route {
	result, err := route.insertSubRoute(path)
	if err != nil {
		panic(err)
	}
	return result
}

func (route *Route) HandleFunc(handlerFunc http.HandlerFunc, methods ...string) *Route {
	return route.Handle(http.HandlerFunc(handlerFunc), methods...)
}

func (route *Route) Handle(handler http.Handler, methods ...string) *Route {
	if route.routeHandler == nil {
		route.routeHandler = &routeHandler{}
	}
	route.routeHandler.handle(handler, methods...)
	return route
}

func (route *Route) ListRoutes() []string {
	result := []string{}
	methodsRoutes := route.listMethodsRoutes()
	for _, v := range methodsRoutes {
		result = append(result, v[0]+" "+v[1])
	}
	return result
}

func (route *Route) listMethodsRoutes() [][]string {
	result := [][]string{}
	if route.routeHandler != nil {
		methodsAll := route.routeHandler.methodsAll()
		for _, v := range methodsAll {
			result = append(result, []string{v, route.path})
		}
	}
	for _, child := range route.children {
		methodsRoutes := child.listMethodsRoutes()
		for _, v := range methodsRoutes {
			result = append(result, []string{v[0], route.path + v[1]})
		}
	}
	return result
}

func (route *Route) getHandler(r *http.Request) (http.Handler, error) {
	if route.routeHandler == nil {
		return nil, errors.ErrNotFound
	}
	return route.routeHandler.getHandler(r)
}

func (route *Route) search(path string) (*Route, *Route, string) {
	return route.findStaticSubRoute(path)
}

func (route *Route) insertSubRoute(path string) (*Route, error) {
	if len(path) == 0 {
{'fraction_non_alphanumeric': 0.1450113975100824, 'fraction_numerical': 0.001753463089601964, 'mean_word_length': 4.7269076305220885, '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': '5667123', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1898, 'n_words': 479}