func Param(r *http.Request, name string) string {
	return r.Context().Value(pattern.Variable(name)).(string)
}
/*
Param returns the bound parameter with the given name. For instance, given the
route:

/user/:name

and the URL Path:

/user/carl

a call to Param(r, "name") would return the string "carl". It is the caller's
responsibility to ensure that the variable has been bound. Attempts to access
variables that have not been set (or which have been invalidly set) are
considered programmer errors and will trigger a panic.
package pat
import (
	"net/http"
	"regexp"
	"sort"
	"strings"
	"goji.io/pattern"
)
type patNames []struct {
	name pattern.Variable
	idx  int
}
func (p patNames) Len() int {
	return len(p)
}
func (p patNames) Less(i, j int) bool {
	return p[i].name < p[j].name
}
func (p patNames) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}
type Pattern struct {
	raw     string
	methods map[string]struct{}
	pats     patNames
	breaks   []byte
	literals []string
	wildcard bool
}
const bc = "/.;,"
var patternRe = regexp.MustCompile(`[` + bc + `]:([^` + bc + `]+)`)
func New(pat string) *Pattern {
	p := &Pattern{raw: pat}
	if strings.HasSuffix(pat, "/*") {
		pat = pat[:len(pat)-1]
		p.wildcard = true
	}
	matches := patternRe.FindAllStringSubmatchIndex(pat, -1)
	numMatches := len(matches)
	p.pats = make(patNames, numMatches)
	p.breaks = make([]byte, numMatches)
	p.literals = make([]string, numMatches+1)
	n := 0
	for i, match := range matches {
		a, b := match[2], match[3]
		p.literals[i] = pat[n : a-1]  
		p.pats[i].name = pattern.Variable(pat[a:b])
		p.pats[i].idx = i
		if b == len(pat) {
			p.breaks[i] = '/'
		} else {
			p.breaks[i] = pat[b]
		}
		n = b
	}
	p.literals[numMatches] = pat[n:]
	sort.Sort(p.pats)
	return p
}
func newWithMethods(pat string, methods ...string) *Pattern {
	p := New(pat)
	methodSet := make(map[string]struct{}, len(methods))
	for _, method := range methods {
		methodSet[method] = struct{}{}
	}
	p.methods = methodSet
	return p
}
func (p *Pattern) Match(r *http.Request) *http.Request {
	if p.methods != nil {
		if _, ok := p.methods[r.Method]; !ok {
			return nil
		}
	}
	ctx := r.Context()
	path := pattern.Path(ctx)
	var scratch []string
	if p.wildcard {
		scratch = make([]string, len(p.pats)+1)
	} else if len(p.pats) > 0 {
		scratch = make([]string, len(p.pats))
	}
	for i := range p.pats {
		sli := p.literals[i]
		if !strings.HasPrefix(path, sli) {
			return nil
		}
		path = path[len(sli):]
		m := 0
		bc := p.breaks[i]
		for ; m < len(path); m++ {
			if path[m] == bc || path[m] == '/' {
				break
			}
		}
		if m == 0 {
			return nil
		}
		scratch[i] = path[:m]
		path = path[m:]
	}
	tail := p.literals[len(p.pats)]
	if p.wildcard {
		if !strings.HasPrefix(path, tail) {
			return nil
		}
		scratch[len(p.pats)] = path[len(tail)-1:]
	} else if path != tail {
		return nil
	}
	for i := range p.pats {
		var err error
		scratch[i], err = unescape(scratch[i])
		if err != nil {
			return nil
		}
	}
	return r.WithContext(&match{ctx, p, scratch})
}
func (p *Pattern) PathPrefix() string {
	return p.literals[0]
}
func (p *Pattern) HTTPMethods() map[string]struct{} {
	return p.methods
}
func (p *Pattern) String() string {
	return p.raw
}