func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	method := r.Method
	normPath := path.Clean(r.URL.Path)
	if normPath != "/" {
		if strings.HasSuffix(r.URL.Path, "/") {
			normPath = normPath + "/"
		}
	}
	if normPath != r.URL.Path {
		http.Redirect(w, r, normPath, http.StatusFound)
		return
	}
	segments := strings.Split(normPath, "/")[1:]
	for _, route := range m.routes {
		var vals map[string]string
		var matched bool
		if route.Method == "ALL" {
			matched = isPrefixMatch(segments, route.Segments)
			if matched {
				vals = make(map[string]string)
				vals["path"] = strings.TrimPrefix(normPath, route.Path)
			}
		} else {
			vals, matched = isMatch(method, segments, &route)
		}
		if matched == false {
			continue
		}
		ctx := context.WithValue(r.Context(), valsIdKey, vals)
		r = r.WithContext(ctx)
		route.Handler.ServeHTTP(w, r)
		return
	}
	http.NotFound(w, r)
}
ServeHTTP makes the router implement the http.Handler interface.
package mux
import (
	"context"
	"errors"
	"net/http"
	"path"
	"strings"
)
type key int
const valsIdKey key = 999
var (
	ErrPathMustStartWithSlash = errors.New("mux: path must start with a slash")
	ErrMultipleHandlers = errors.New("mux: route has been given two handlers but only one can be provider")
	ErrMiddlewareAfterHandler = errors.New("mux: route can't have middleware defined after the handler")
	ErrUnknownTypeInRoute = errors.New("mux: unexpected type passed to route")
)
type Route struct {
	Method      string
	Path        string
	Segments    []string
	Length      int
	Middlewares []func(http.Handler) http.Handler
	Handler     http.Handler
}
type Prefix struct {
	Path        string
	Segments    []string
	Length      int
	Middlewares []func(http.Handler) http.Handler
	Handler     http.Handler
}
type Mux struct {
	routes   []Route
	prefixes []Prefix
	Err      error
}
var _ http.Handler = New()
func New() *Mux {
	return &Mux{}
}
func (m *Mux) Get(path string, things ...interface{}) {
	m.add("GET", path, things...)
}
func (m *Mux) Post(path string, things ...interface{}) {
	m.add("POST", path, things...)
}
func (m *Mux) Put(path string, things ...interface{}) {
	m.add("PUT", path, things...)
}
func (m *Mux) Patch(path string, things ...interface{}) {
	m.add("PATCH", path, things...)
}
func (m *Mux) Delete(path string, things ...interface{}) {
	m.add("DELETE", path, things...)
}
func (m *Mux) Options(path string, things ...interface{}) {
	m.add("OPTIONS", path, things...)
}
func (m *Mux) Head(path string, things ...interface{}) {
	m.add("HEAD", path, things...)
}
func (m *Mux) Use(path string, things ...interface{}) {
	m.add("USE", path, things...)
}
func (m *Mux) All(path string, things ...interface{}) {
	m.add("ALL", path, things...)
}
func (m *Mux) add(method, path string, things ...interface{}) {
	if m.Err != nil {
		return
	}
	if len(path) == 0 || path[0] != '/' {
		m.Err = ErrPathMustStartWithSlash
		return
	}
	if m.routes == nil {
		m.routes = make([]Route, 0)
	}
	var handler http.Handler
	var middlewares []func(http.Handler) http.Handler
	segments := strings.Split(path, "/")[1:]
	for _, thing := range things {
		switch val := thing.(type) {
		case func(http.Handler) http.Handler:
			if handler != nil {
				m.Err = ErrMiddlewareAfterHandler
				return
			}
			middlewares = append(middlewares, val)
		case func(http.HandlerFunc) http.HandlerFunc:
			if handler != nil {
				m.Err = ErrMiddlewareAfterHandler
				return
			}
			setup := func(next http.Handler) http.Handler {
				myNext := func(w http.ResponseWriter, r *http.Request) {
					next.ServeHTTP(w, r)
				}
				return http.Handler(val(myNext))
			}
			middlewares = append(middlewares, setup)
		case http.Handler:
			if handler != nil {
				m.Err = ErrMultipleHandlers
				return
			}
			handler = val
		case func(http.ResponseWriter, *http.Request):
			if handler != nil {
				m.Err = ErrMultipleHandlers
				return
			}
			handler = http.HandlerFunc(val)
		default:
			m.Err = ErrUnknownTypeInRoute
			return
		}
	}
	if method == "USE" {
		if handler != nil {
		}
		prefix := Prefix{
			Path:        path,
			Segments:    segments,
			Length:      len(segments),
			Middlewares: middlewares,
			Handler:     handler,
		}
		m.prefixes = append(m.prefixes, prefix)
	} else {
		wrappedHandler := handler
		for i := range middlewares {
			middleware := middlewares[len(middlewares)-1-i]
			wrappedHandler = middleware(wrappedHandler)
		}
		for j := range m.prefixes {
			prefix := m.prefixes[len(m.prefixes)-1-j]
			if isPrefixMatch(segments, prefix.Segments) {
				for i := range prefix.Middlewares {
					middleware := prefix.Middlewares[len(prefix.Middlewares)-1-i]
					wrappedHandler = middleware(wrappedHandler)
				}
			}
		}
		route := Route{
			Method:      method,
			Path:        path,
			Segments:    segments,
			Length:      len(segments),
			Middlewares: nil,  
			Handler:     wrappedHandler,
		}
		m.routes = append(m.routes, route)
	}
}
func isPrefixMatch(segments []string, prefixSegments []string) bool {
	prefixLength := len(prefixSegments)
	if prefixLength == 1 && prefixSegments[0] == "" {
		return true
	}
	if prefixLength > len(segments) {
		return false
	}
	for i, segment := range prefixSegments {
		if segment == "" && segments[i] == "" {
			continue
		}
		if segment[0:0] == ":" {
			continue
		}
		if segments[i] != segment {
			return false
		}
	}
	return true
}
func isMatch(method string, segments []string, route *Route) (map[string]string, bool) {
	if route.Method != method {
		return nil, false
	}
	if route.Length != len(segments) {
		return nil, false
	}
	vals := make(map[string]string)
	for i, segment := range route.Segments {
		if segment == "" && segments[i] == "" {
			continue
		}
		if segment != "" && segment[0:1] == ":" {
			vals[segment[1:]] = segments[i]
			continue
		}
		if segments[i] != segment {
			return nil, false
		}
	}
	return vals, true
}