func GetParam(r *http.Request, key string) string {
	return GetAllParams(r)[key]
}
GetParam returns route param stored in http.request.
package gorouter
import (
	"context"
	"errors"
	"fmt"
	"net/http"
	"regexp"
	"strings"
)
var (
	ErrGenerateParameters = errors.New("params contains wrong parameters")
	ErrNotFoundRoute = errors.New("cannot find route in tree")
	ErrNotFoundMethod = errors.New("cannot find method in tree")
	ErrPatternGrammar = errors.New("pattern grammar error")
	defaultPattern = `[\w]+`
	idPattern      = `[\d]+`
	idKey          = `id`
	methods = map[string]struct{}{
		http.MethodGet:    {},
		http.MethodPost:   {},
		http.MethodPut:    {},
		http.MethodDelete: {},
		http.MethodPatch:  {},
		http.MethodHead:   {},
	}
)
type (
	MiddlewareType func(next http.HandlerFunc) http.HandlerFunc
	Router struct {
		prefix string
		middleware []MiddlewareType
		trees      map[string]*Tree
		parameters Parameters
		notFound http.HandlerFunc
		PanicHandler func(w http.ResponseWriter, req *http.Request, err interface{})
	}
	Parameters struct {
		routeName string
	}
)
func New() *Router {
	return &Router{
		trees: make(map[string]*Tree),
	}
}
func (r *Router) GET(path string, handle http.HandlerFunc) {
	r.Handle(http.MethodGet, path, handle)
}
func (r *Router) POST(path string, handle http.HandlerFunc) {
	r.Handle(http.MethodPost, path, handle)
}
func (r *Router) DELETE(path string, handle http.HandlerFunc) {
	r.Handle(http.MethodDelete, path, handle)
}
func (r *Router) PUT(path string, handle http.HandlerFunc) {
	r.Handle(http.MethodPut, path, handle)
}
func (r *Router) PATCH(path string, handle http.HandlerFunc) {
	r.Handle(http.MethodPatch, path, handle)
}
func (r *Router) HEAD(path string, handle http.HandlerFunc) {
	r.Handle(http.MethodHead, path, handle)
}
func (r *Router) GETAndName(path string, handle http.HandlerFunc, routeName string) {
	r.parameters.routeName = routeName
	r.GET(path, handle)
}
func (r *Router) POSTAndName(path string, handle http.HandlerFunc, routeName string) {
	r.parameters.routeName = routeName
	r.POST(path, handle)
}
func (r *Router) DELETEAndName(path string, handle http.HandlerFunc, routeName string) {
	r.parameters.routeName = routeName
	r.DELETE(path, handle)
}
func (r *Router) PUTAndName(path string, handle http.HandlerFunc, routeName string) {
	r.parameters.routeName = routeName
	r.PUT(path, handle)
}
func (r *Router) PATCHAndName(path string, handle http.HandlerFunc, routeName string) {
	r.parameters.routeName = routeName
	r.PATCH(path, handle)
}
func (r *Router) HEADAndName(path string, handle http.HandlerFunc, routeName string) {
	r.parameters.routeName = routeName
	r.HEAD(path, handle)
}
func (r *Router) Group(prefix string) *Router {
	return &Router{
		prefix:     prefix,
		trees:      r.trees,
		middleware: r.middleware,
	}
}
func (r *Router) Generate(method string, routeName string, params map[string]string) (string, error) {
	tree, ok := r.trees[method]
	if !ok {
		return "", ErrNotFoundMethod
	}
	route, ok := tree.routes[routeName]
	if !ok {
		return "", ErrNotFoundRoute
	}
	var segments []string
	res := splitPattern(route.path)
	for _, segment := range res {
		if string(segment[0]) == ":" {
			key := params[string(segment[1:])]
			re := regexp.MustCompile(defaultPattern)
			if one := re.Find([]byte(key)); one == nil {
				return "", ErrGenerateParameters
			}
			segments = append(segments, key)
			continue
		}
		if string(segment[0]) == "{" {
			segmentLen := len(segment)
			if string(segment[segmentLen-1]) == "}" {
				splitRes := strings.Split(string(segment[1:segmentLen-1]), ":")
				re := regexp.MustCompile(splitRes[1])
				key := params[splitRes[0]]
				if one := re.Find([]byte(key)); one == nil {
					return "", ErrGenerateParameters
				}
				segments = append(segments, key)
				continue
			}
			return "", ErrPatternGrammar
		}
		if string(segment[len(segment)-1]) == "}" && string(segment[0]) != "{" {
			return "", ErrPatternGrammar
		}
		segments = append(segments, segment)
		continue
	}
	return "/" + strings.Join(segments, "/"), nil
}
func (r *Router) NotFoundFunc(handler http.HandlerFunc) {
	r.notFound = handler
}
func (r *Router) Handle(method string, path string, handle http.HandlerFunc) {
	if _, ok := methods[method]; !ok {
		panic(fmt.Errorf("invalid method"))
	}
	tree, ok := r.trees[method]
	if !ok {
		tree = NewTree()
		r.trees[method] = tree
	}
	if r.prefix != "" {
		path = r.prefix + "/" + path
	}
	if routeName := r.parameters.routeName; routeName != "" {
		tree.parameters.routeName = routeName
	}
	tree.Add(path, handle, r.middleware...)
}