<commit_before>package napnap

import "strings"

type (
	Router struct {
		tree *tree
	}

	tree struct {
		rootNode *node
	}
	kind uint8
	node struct {
		parent    *node
		children  []*node
		kind      kind
		name      string
		pNames    []string
		params    []string
		sortOrder int
		handler   *methodHandler
	}
	methodHandler struct {
		connect HandlerFunc
		delete  HandlerFunc
		get     HandlerFunc
		head    HandlerFunc
		options HandlerFunc
		patch   HandlerFunc
		post    HandlerFunc
		put     HandlerFunc
		trace   HandlerFunc
	}
)

const (
	// CONNECT HTTP method
	CONNECT = "CONNECT"
	// DELETE HTTP method
	DELETE = "DELETE"
	// GET HTTP method
	GET = "GET"
	// HEAD HTTP method
	HEAD = "HEAD"
	// OPTIONS HTTP method
	OPTIONS = "OPTIONS"
	// PATCH HTTP method
	PATCH = "PATCH"
	// POST HTTP method
	POST = "POST"
	// PUT HTTP method
	PUT = "PUT"
	// TRACE HTTP method
	TRACE = "TRACE"
)

var (
	notFoundHandler = func(c *Context) {
		println("NotFound")
	}
)

const (
	skind kind = iota
	pkind
)

// NewRouter function will create a new router instance
func NewRouter() *Router {
	return &Router{
		tree: &tree{
			rootNode: &node{
				parent:    nil,
				children:  []*node{},
				kind:      0,
				name:      "/",
				sortOrder: 0,
				handler:   &methodHandler{},
			},
		},
	}
}

// Invoke function is a middleware entry
func (r *Router) Invoke(c *Context, next HandlerFunc) {
	h := r.Find(c.Request.Method, c.Request.URL.Path, c)

	if h == nil {
		next(c)
	} else {
		h(c)
	}
}

// Get is a shortcut for router.Add("GET", path, handle)
func (r *Router) Get(path string, handler HandlerFunc) {
	r.Add(GET, path, handler)
}

// Post is a shortcut for router.Add("POST", path, handle)
func (r *Router) Post(path string, handler HandlerFunc) {
	r.Add(POST, path, handler)
}

// Put is a shortcut for router.Add("PUT", path, handle)
func (r *Router) Put(path string, handler HandlerFunc) {
	r.Add(PUT, path, handler)
}

// Delete is a shortcut for router.Add("DELETE", path, handle)
func (r *Router) Delete(path string, handler HandlerFunc) {
	r.Add(DELETE, path, handler)
}

// Patch is a shortcut for router.Add("PATCH", path, handle)
func (r *Router) Patch(path string, handler HandlerFunc) {
	r.Add(PATCH, path, handler)<commit_msg>added "all" function in Router<commit_after>package napnap

import "strings"

type (
	Router struct {
		tree *tree
	}

	tree struct {
		rootNode *node
	}
	kind uint8
	node struct {
		parent    *node
		children  []*node
		kind      kind
		name      string
		pNames    []string
		params    []string
		sortOrder int
		handler   *methodHandler
	}
	methodHandler struct {
		connect HandlerFunc
		delete  HandlerFunc
		get     HandlerFunc
		head    HandlerFunc
		options HandlerFunc
		patch   HandlerFunc
		post    HandlerFunc
		put     HandlerFunc
		trace   HandlerFunc
	}
)

const (
	// CONNECT HTTP method
	CONNECT = "CONNECT"
	// DELETE HTTP method
	DELETE = "DELETE"
	// GET HTTP method
	GET = "GET"
	// HEAD HTTP method
	HEAD = "HEAD"
	// OPTIONS HTTP method
	OPTIONS = "OPTIONS"
	// PATCH HTTP method
	PATCH = "PATCH"
	// POST HTTP method
	POST = "POST"
	// PUT HTTP method
	PUT = "PUT"
	// TRACE HTTP method
	TRACE = "TRACE"
)

var (
	notFoundHandler = func(c *Context) {
		println("NotFound")
	}
)

const (
	skind kind = iota
	pkind
)

// NewRouter function will create a new router instance
func NewRouter() *Router {
	return &Router{
		tree: &tree{
			rootNode: &node{
				parent:    nil,
				children:  []*node{},
				kind:      0,
				name:      "/",
				sortOrder: 0,
				handler:   &methodHandler{},
			},
		},
	}
}

// Invoke function is a middleware entry
func (r *Router) Invoke(c *Context, next HandlerFunc) {
	h := r.Find(c.Request.Method, c.Request.URL.Path, c)

	if h == nil {
		next(c)
	} else {
		h(c)
	}
}

// All is a shortcut for adding all methods
func (r *Router) All(path string, handler HandlerFunc) {
	r.Add(GET, path, handler)
	r.Add(POST, path, handler)
	r.Add(PUT, path, handler)
	r.Add(DELETE, path, handler)
	r.Add(PATCH, path, handler)
	r.Add(OPTIONS, path, handler)
	r.Add(HEAD, path, handler)
}

// Get is a shortcut for router.Add("GET", path, handle)
func (r *Router) Get(path string, handler HandlerFunc) {
	r.Add(GET, path, handler)
}

// Post is a shortcut for router.Add("POST", path, handle)
func (r *Router) Post(path string, handler HandlerFunc) {
	r.Add(POST, path, handler)
}

// Put is a shortcut for router.Add("PUT", path, handle)
func (r *Router) Put(path string, handler HandlerFunc) {
	r.Add(PUT, path, handler)
}

// Delete is a shortcut for router.Add("DELETE", path, handle)
func (r *Router) Delete(path string, handler HandlerFunc) {
	r.Add(DELETE, path, handler)
}

// Patch is a shortcut for router.Add("PATCH", path, handle)
func (r *Router) Patch(path string, handler HandlerFunc) {
	r.Add(PATCH, path, handler)
{'fraction_non_alphanumeric': 0.12305457563809918, 'fraction_numerical': 0.0012450715916165179, 'mean_word_length': 3.1021276595744682, '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': '4275876', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1680, 'n_words': 539}