2015-03-27 23:21:30 +02:00
|
|
|
package echo
|
2015-03-01 19:45:13 +02:00
|
|
|
|
2015-07-30 23:43:22 +02:00
|
|
|
import "net/http"
|
2015-03-01 19:45:13 +02:00
|
|
|
|
|
|
|
type (
|
2015-05-23 05:26:52 +02:00
|
|
|
Router struct {
|
2015-07-24 21:03:36 +02:00
|
|
|
connectTree *node
|
|
|
|
deleteTree *node
|
|
|
|
getTree *node
|
|
|
|
headTree *node
|
|
|
|
optionsTree *node
|
|
|
|
patchTree *node
|
|
|
|
postTree *node
|
|
|
|
putTree *node
|
|
|
|
traceTree *node
|
|
|
|
routes []Route
|
|
|
|
echo *Echo
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
node struct {
|
2015-04-24 16:44:30 +02:00
|
|
|
typ ntype
|
2015-04-14 06:57:36 +02:00
|
|
|
label byte
|
|
|
|
prefix string
|
|
|
|
parent *node
|
|
|
|
children children
|
2015-05-04 22:01:02 +02:00
|
|
|
handler HandlerFunc
|
|
|
|
pnames []string
|
|
|
|
echo *Echo
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
2015-04-24 16:44:30 +02:00
|
|
|
ntype uint8
|
2015-04-14 06:57:36 +02:00
|
|
|
children []*node
|
2015-03-01 19:45:13 +02:00
|
|
|
)
|
|
|
|
|
2015-04-24 16:44:30 +02:00
|
|
|
const (
|
|
|
|
stype ntype = iota
|
|
|
|
ptype
|
2015-04-29 08:09:30 +02:00
|
|
|
mtype
|
2015-04-24 16:44:30 +02:00
|
|
|
)
|
|
|
|
|
2015-07-27 17:43:11 +02:00
|
|
|
func NewRouter(e *Echo) *Router {
|
|
|
|
return &Router{
|
2015-07-24 21:03:36 +02:00
|
|
|
connectTree: new(node),
|
|
|
|
deleteTree: new(node),
|
|
|
|
getTree: new(node),
|
|
|
|
headTree: new(node),
|
|
|
|
optionsTree: new(node),
|
|
|
|
patchTree: new(node),
|
|
|
|
postTree: new(node),
|
|
|
|
putTree: new(node),
|
|
|
|
traceTree: new(node),
|
2015-07-27 17:43:11 +02:00
|
|
|
routes: []Route{},
|
|
|
|
echo: e,
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 00:18:27 +02:00
|
|
|
func (r *Router) Add(method, path string, h HandlerFunc, e *Echo) {
|
|
|
|
pnames := []string{} // Param names
|
2015-04-24 16:44:30 +02:00
|
|
|
|
2015-04-05 23:21:03 +02:00
|
|
|
for i, l := 0, len(path); i < l; i++ {
|
2015-03-01 19:45:13 +02:00
|
|
|
if path[i] == ':' {
|
2015-04-24 16:44:30 +02:00
|
|
|
j := i + 1
|
|
|
|
|
2015-06-04 00:18:27 +02:00
|
|
|
r.insert(method, path[:i], nil, stype, nil, e)
|
2015-03-01 19:45:13 +02:00
|
|
|
for ; i < l && path[i] != '/'; i++ {
|
|
|
|
}
|
2015-04-24 16:44:30 +02:00
|
|
|
|
|
|
|
pnames = append(pnames, path[j:i])
|
|
|
|
path = path[:j] + path[i:]
|
|
|
|
i, l = j, len(path)
|
|
|
|
|
2015-03-01 19:45:13 +02:00
|
|
|
if i == l {
|
2015-06-04 00:18:27 +02:00
|
|
|
r.insert(method, path[:i], h, ptype, pnames, e)
|
2015-03-01 19:45:13 +02:00
|
|
|
return
|
|
|
|
}
|
2015-06-04 00:18:27 +02:00
|
|
|
r.insert(method, path[:i], nil, ptype, pnames, e)
|
2015-03-07 07:55:51 +02:00
|
|
|
} else if path[i] == '*' {
|
2015-06-04 00:18:27 +02:00
|
|
|
r.insert(method, path[:i], nil, stype, nil, e)
|
2015-09-17 17:11:35 +02:00
|
|
|
pnames = append(pnames, "_*")
|
2015-09-15 22:14:30 +02:00
|
|
|
r.insert(method, path[:i+1], h, mtype, pnames, e)
|
2015-04-26 18:48:49 +02:00
|
|
|
return
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-04 00:18:27 +02:00
|
|
|
|
|
|
|
r.insert(method, path, h, stype, pnames, e)
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
|
2015-06-04 00:18:27 +02:00
|
|
|
func (r *Router) insert(method, path string, h HandlerFunc, t ntype, pnames []string, e *Echo) {
|
|
|
|
// Adjust max param
|
|
|
|
l := len(pnames)
|
|
|
|
if *e.maxParam < l {
|
|
|
|
*e.maxParam = l
|
|
|
|
}
|
|
|
|
|
2015-07-24 21:03:36 +02:00
|
|
|
cn := r.findTree(method) // Current node as root
|
|
|
|
if cn == nil {
|
|
|
|
panic("echo => invalid method")
|
|
|
|
}
|
2015-03-01 19:45:13 +02:00
|
|
|
search := path
|
|
|
|
|
|
|
|
for {
|
|
|
|
sl := len(search)
|
|
|
|
pl := len(cn.prefix)
|
2015-06-06 00:08:32 +02:00
|
|
|
l := 0
|
|
|
|
|
|
|
|
// LCP
|
|
|
|
max := pl
|
|
|
|
if sl < max {
|
|
|
|
max = sl
|
|
|
|
}
|
|
|
|
for ; l < max && search[l] == cn.prefix[l]; l++ {
|
|
|
|
}
|
2015-03-01 19:45:13 +02:00
|
|
|
|
|
|
|
if l == 0 {
|
|
|
|
// At root node
|
|
|
|
cn.label = search[0]
|
|
|
|
cn.prefix = search
|
|
|
|
if h != nil {
|
2015-04-24 16:44:30 +02:00
|
|
|
cn.typ = t
|
2015-04-01 17:05:54 +02:00
|
|
|
cn.handler = h
|
2015-04-24 16:44:30 +02:00
|
|
|
cn.pnames = pnames
|
2015-06-04 00:18:27 +02:00
|
|
|
cn.echo = e
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
} else if l < pl {
|
2015-04-08 23:40:49 +02:00
|
|
|
// Split node
|
2015-05-01 03:47:13 +02:00
|
|
|
n := newNode(cn.typ, cn.prefix[l:], cn, cn.children, cn.handler, cn.pnames, cn.echo)
|
2015-03-01 19:45:13 +02:00
|
|
|
|
|
|
|
// Reset parent node
|
2015-04-24 16:44:30 +02:00
|
|
|
cn.typ = stype
|
2015-03-01 19:45:13 +02:00
|
|
|
cn.label = cn.prefix[0]
|
|
|
|
cn.prefix = cn.prefix[:l]
|
2015-06-06 00:08:32 +02:00
|
|
|
cn.children = nil
|
2015-04-01 17:05:54 +02:00
|
|
|
cn.handler = nil
|
2015-04-24 16:44:30 +02:00
|
|
|
cn.pnames = nil
|
2015-04-02 23:41:36 +02:00
|
|
|
cn.echo = nil
|
2015-03-01 19:45:13 +02:00
|
|
|
|
2015-06-06 00:08:32 +02:00
|
|
|
cn.addChild(n)
|
|
|
|
|
2015-03-01 19:45:13 +02:00
|
|
|
if l == sl {
|
|
|
|
// At parent node
|
2015-04-24 16:44:30 +02:00
|
|
|
cn.typ = t
|
2015-04-01 17:05:54 +02:00
|
|
|
cn.handler = h
|
2015-04-24 16:44:30 +02:00
|
|
|
cn.pnames = pnames
|
2015-06-04 00:18:27 +02:00
|
|
|
cn.echo = e
|
2015-03-01 19:45:13 +02:00
|
|
|
} else {
|
2015-04-08 23:40:49 +02:00
|
|
|
// Create child node
|
2015-06-04 00:18:27 +02:00
|
|
|
n = newNode(t, search[l:], cn, nil, h, pnames, e)
|
2015-06-06 00:08:32 +02:00
|
|
|
cn.addChild(n)
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
} else if l < sl {
|
|
|
|
search = search[l:]
|
2015-06-06 00:08:32 +02:00
|
|
|
c := cn.findChildWithLabel(search[0])
|
2015-04-14 06:57:36 +02:00
|
|
|
if c != nil {
|
2015-04-08 23:40:49 +02:00
|
|
|
// Go deeper
|
2015-04-14 06:57:36 +02:00
|
|
|
cn = c
|
2015-04-08 23:40:49 +02:00
|
|
|
continue
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
2015-04-08 23:40:49 +02:00
|
|
|
// Create child node
|
2015-06-04 00:18:27 +02:00
|
|
|
n := newNode(t, search, cn, nil, h, pnames, e)
|
2015-06-06 00:08:32 +02:00
|
|
|
cn.addChild(n)
|
2015-03-01 19:45:13 +02:00
|
|
|
} else {
|
|
|
|
// Node already exists
|
|
|
|
if h != nil {
|
2015-04-01 17:05:54 +02:00
|
|
|
cn.handler = h
|
2015-04-24 16:44:30 +02:00
|
|
|
cn.pnames = pnames
|
2015-06-04 00:18:27 +02:00
|
|
|
cn.echo = e
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-08 23:40:49 +02:00
|
|
|
return
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 00:18:27 +02:00
|
|
|
func newNode(t ntype, pre string, p *node, c children, h HandlerFunc, pnames []string, e *Echo) *node {
|
2015-04-26 21:44:38 +02:00
|
|
|
return &node{
|
2015-04-24 16:44:30 +02:00
|
|
|
typ: t,
|
2015-05-14 00:20:09 +02:00
|
|
|
label: pre[0],
|
|
|
|
prefix: pre,
|
2015-04-14 06:57:36 +02:00
|
|
|
parent: p,
|
|
|
|
children: c,
|
|
|
|
handler: h,
|
2015-04-24 16:44:30 +02:00
|
|
|
pnames: pnames,
|
2015-06-04 00:18:27 +02:00
|
|
|
echo: e,
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
2015-04-26 21:44:38 +02:00
|
|
|
}
|
|
|
|
|
2015-06-06 00:08:32 +02:00
|
|
|
func (n *node) addChild(c *node) {
|
|
|
|
n.children = append(n.children, c)
|
2015-04-01 17:05:54 +02:00
|
|
|
}
|
|
|
|
|
2015-06-06 00:08:32 +02:00
|
|
|
func (n *node) findChild(l byte, t ntype) *node {
|
2015-04-24 16:44:30 +02:00
|
|
|
for _, c := range n.children {
|
2015-06-06 00:08:32 +02:00
|
|
|
if c.label == l && c.typ == t {
|
2015-04-24 16:44:30 +02:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-06 00:08:32 +02:00
|
|
|
func (n *node) findChildWithLabel(l byte) *node {
|
2015-04-24 16:44:30 +02:00
|
|
|
for _, c := range n.children {
|
2015-06-06 00:08:32 +02:00
|
|
|
if c.label == l {
|
2015-04-24 16:44:30 +02:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-06 00:08:32 +02:00
|
|
|
func (n *node) findChildWithType(t ntype) *node {
|
2015-04-24 16:44:30 +02:00
|
|
|
for _, c := range n.children {
|
2015-06-06 00:08:32 +02:00
|
|
|
if c.typ == t {
|
2015-04-24 16:44:30 +02:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-24 21:03:36 +02:00
|
|
|
func (r *Router) findTree(method string) (n *node) {
|
|
|
|
switch method[0] {
|
|
|
|
case 'G': // GET
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint32(method[2])<<8 | uint32(method[1])<<16 | uint32(method[0])<<24
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x47455400 {
|
|
|
|
n = r.getTree
|
|
|
|
}
|
2015-07-30 18:29:13 +02:00
|
|
|
case 'P': // POST, PUT or PATCH
|
2015-07-24 21:03:36 +02:00
|
|
|
switch method[1] {
|
|
|
|
case 'O': // POST
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint32(method[3]) | uint32(method[2])<<8 | uint32(method[1])<<16 |
|
|
|
|
uint32(method[0])<<24
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x504f5354 {
|
|
|
|
n = r.postTree
|
|
|
|
}
|
|
|
|
case 'U': // PUT
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint32(method[2])<<8 | uint32(method[1])<<16 | uint32(method[0])<<24
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x50555400 {
|
|
|
|
n = r.putTree
|
|
|
|
}
|
|
|
|
case 'A': // PATCH
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint64(method[4])<<24 | uint64(method[3])<<32 | uint64(method[2])<<40 |
|
|
|
|
uint64(method[1])<<48 | uint64(method[0])<<56
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x5041544348000000 {
|
|
|
|
n = r.patchTree
|
|
|
|
}
|
|
|
|
}
|
2015-07-30 18:29:13 +02:00
|
|
|
case 'D': // DELETE
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint64(method[5])<<16 | uint64(method[4])<<24 | uint64(method[3])<<32 |
|
|
|
|
uint64(method[2])<<40 | uint64(method[1])<<48 | uint64(method[0])<<56
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x44454c4554450000 {
|
|
|
|
n = r.deleteTree
|
|
|
|
}
|
2015-07-30 18:29:13 +02:00
|
|
|
case 'C': // CONNECT
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint64(method[6])<<8 | uint64(method[5])<<16 | uint64(method[4])<<24 |
|
|
|
|
uint64(method[3])<<32 | uint64(method[2])<<40 | uint64(method[1])<<48 |
|
|
|
|
uint64(method[0])<<56
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x434f4e4e45435400 {
|
|
|
|
n = r.connectTree
|
|
|
|
}
|
2015-07-30 18:29:13 +02:00
|
|
|
case 'H': // HEAD
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint32(method[3]) | uint32(method[2])<<8 | uint32(method[1])<<16 |
|
|
|
|
uint32(method[0])<<24
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x48454144 {
|
|
|
|
n = r.headTree
|
|
|
|
}
|
2015-07-30 18:29:13 +02:00
|
|
|
case 'O': // OPTIONS
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint64(method[6])<<8 | uint64(method[5])<<16 | uint64(method[4])<<24 |
|
|
|
|
uint64(method[3])<<32 | uint64(method[2])<<40 | uint64(method[1])<<48 |
|
|
|
|
uint64(method[0])<<56
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x4f5054494f4e5300 {
|
2015-07-30 18:29:13 +02:00
|
|
|
n = r.optionsTree
|
2015-07-24 21:03:36 +02:00
|
|
|
}
|
2015-07-30 18:29:13 +02:00
|
|
|
case 'T': // TRACE
|
2015-09-15 22:14:30 +02:00
|
|
|
m := uint64(method[4])<<24 | uint64(method[3])<<32 | uint64(method[2])<<40 |
|
|
|
|
uint64(method[1])<<48 | uint64(method[0])<<56
|
2015-07-24 21:03:36 +02:00
|
|
|
if m == 0x5452414345000000 {
|
|
|
|
n = r.traceTree
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-06-04 00:18:27 +02:00
|
|
|
func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo) {
|
2015-07-24 21:03:36 +02:00
|
|
|
h = notFoundHandler
|
|
|
|
cn := r.findTree(method) // Current node as root
|
|
|
|
if cn == nil {
|
|
|
|
h = badRequestHandler
|
2015-07-21 21:46:50 +02:00
|
|
|
return
|
|
|
|
}
|
2015-09-01 17:03:01 +02:00
|
|
|
|
|
|
|
// Strip trailing slash
|
|
|
|
if r.echo.stripTrailingSlash {
|
|
|
|
l := len(path)
|
2015-09-21 15:50:32 +02:00
|
|
|
if path != "/" && path[l-1] == '/' { // Issue #218
|
2015-09-15 22:14:30 +02:00
|
|
|
path = path[:l-1]
|
2015-09-01 17:03:01 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-10 07:06:13 +02:00
|
|
|
|
|
|
|
var (
|
2015-09-01 17:03:01 +02:00
|
|
|
search = path
|
2015-09-15 22:14:30 +02:00
|
|
|
c *node // Child node
|
|
|
|
n int // Param counter
|
|
|
|
nt ntype // Next type
|
|
|
|
nn *node // Next node
|
|
|
|
ns string // Next search
|
2015-05-10 07:06:13 +02:00
|
|
|
)
|
2015-03-01 19:45:13 +02:00
|
|
|
|
2015-04-29 08:09:30 +02:00
|
|
|
// Search order static > param > match-any
|
2015-03-01 19:45:13 +02:00
|
|
|
for {
|
2015-05-04 22:01:02 +02:00
|
|
|
if search == "" {
|
2015-07-27 17:43:11 +02:00
|
|
|
if cn.handler != nil {
|
|
|
|
// Found
|
|
|
|
ctx.pnames = cn.pnames
|
|
|
|
h = cn.handler
|
|
|
|
e = cn.echo
|
|
|
|
}
|
2015-04-29 08:09:30 +02:00
|
|
|
return
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
pl := 0 // Prefix length
|
|
|
|
l := 0 // LCP length
|
|
|
|
|
|
|
|
if cn.label != ':' {
|
2015-06-06 00:08:32 +02:00
|
|
|
sl := len(search)
|
2015-05-10 07:06:13 +02:00
|
|
|
pl = len(cn.prefix)
|
2015-06-06 00:08:32 +02:00
|
|
|
|
|
|
|
// LCP
|
|
|
|
max := pl
|
2015-06-10 05:06:51 +02:00
|
|
|
if sl < max {
|
2015-06-06 00:08:32 +02:00
|
|
|
max = sl
|
|
|
|
}
|
|
|
|
for ; l < max && search[l] == cn.prefix[l]; l++ {
|
|
|
|
}
|
2015-05-10 07:06:13 +02:00
|
|
|
}
|
2015-04-13 22:12:30 +02:00
|
|
|
|
2015-04-11 22:49:45 +02:00
|
|
|
if l == pl {
|
2015-05-04 22:01:02 +02:00
|
|
|
// Continue search
|
2015-04-11 22:49:45 +02:00
|
|
|
search = search[l:]
|
2015-05-10 07:06:13 +02:00
|
|
|
} else {
|
|
|
|
cn = nn
|
|
|
|
search = ns
|
|
|
|
if nt == ptype {
|
|
|
|
goto Param
|
|
|
|
} else if nt == mtype {
|
|
|
|
goto MatchAny
|
|
|
|
} else {
|
|
|
|
// Not found
|
|
|
|
return
|
|
|
|
}
|
2015-04-11 20:10:19 +02:00
|
|
|
}
|
2015-03-01 19:45:13 +02:00
|
|
|
|
2015-05-04 22:01:02 +02:00
|
|
|
if search == "" {
|
2015-09-17 04:28:09 +02:00
|
|
|
if cn.handler == nil {
|
|
|
|
// Look up for match-any, might have an empty value for *, e.g.
|
|
|
|
// serving a directory. Issue #207
|
|
|
|
cn = cn.findChildWithType(mtype)
|
2015-09-17 17:11:35 +02:00
|
|
|
ctx.pvalues[len(cn.pnames)-1] = ""
|
2015-05-04 22:01:02 +02:00
|
|
|
}
|
2015-09-17 04:28:09 +02:00
|
|
|
continue
|
2015-05-04 22:01:02 +02:00
|
|
|
}
|
|
|
|
|
2015-04-11 19:09:41 +02:00
|
|
|
// Static node
|
2015-06-06 00:08:32 +02:00
|
|
|
c = cn.findChild(search[0], stype)
|
2015-04-26 21:44:38 +02:00
|
|
|
if c != nil {
|
2015-05-10 07:06:13 +02:00
|
|
|
// Save next
|
|
|
|
if cn.label == '/' {
|
|
|
|
nt = ptype
|
|
|
|
nn = cn
|
|
|
|
ns = search
|
|
|
|
}
|
2015-04-26 21:44:38 +02:00
|
|
|
cn = c
|
2015-04-11 19:09:41 +02:00
|
|
|
continue
|
|
|
|
}
|
2015-04-04 19:44:48 +02:00
|
|
|
|
2015-04-11 19:09:41 +02:00
|
|
|
// Param node
|
2015-09-15 22:14:30 +02:00
|
|
|
Param:
|
2015-06-06 00:08:32 +02:00
|
|
|
c = cn.findChildWithType(ptype)
|
2015-04-26 21:44:38 +02:00
|
|
|
if c != nil {
|
2015-05-10 07:06:13 +02:00
|
|
|
// Save next
|
|
|
|
if cn.label == '/' {
|
|
|
|
nt = mtype
|
|
|
|
nn = cn
|
|
|
|
ns = search
|
|
|
|
}
|
2015-04-26 21:44:38 +02:00
|
|
|
cn = c
|
2015-04-11 19:09:41 +02:00
|
|
|
i, l := 0, len(search)
|
|
|
|
for ; i < l && search[i] != '/'; i++ {
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
2015-04-26 21:44:38 +02:00
|
|
|
ctx.pvalues[n] = search[:i]
|
2015-04-26 18:48:49 +02:00
|
|
|
n++
|
2015-04-11 19:09:41 +02:00
|
|
|
search = search[i:]
|
|
|
|
continue
|
|
|
|
}
|
2015-04-04 19:44:48 +02:00
|
|
|
|
2015-05-04 22:01:02 +02:00
|
|
|
// Match-any node
|
2015-09-15 22:14:30 +02:00
|
|
|
MatchAny:
|
2015-09-17 04:28:09 +02:00
|
|
|
// c = cn.getChild()
|
2015-06-06 00:08:32 +02:00
|
|
|
c = cn.findChildWithType(mtype)
|
2015-05-01 03:47:13 +02:00
|
|
|
if c != nil {
|
|
|
|
cn = c
|
2015-09-17 17:11:35 +02:00
|
|
|
ctx.pvalues[len(cn.pnames)-1] = search
|
2015-05-04 22:01:02 +02:00
|
|
|
search = "" // End search
|
2015-05-10 17:22:49 +02:00
|
|
|
continue
|
2015-04-12 22:04:41 +02:00
|
|
|
}
|
2015-06-06 00:08:32 +02:00
|
|
|
|
2015-05-10 17:22:49 +02:00
|
|
|
// Not found
|
|
|
|
return
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 05:26:52 +02:00
|
|
|
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
2015-04-09 23:59:31 +02:00
|
|
|
c := r.echo.pool.Get().(*Context)
|
2015-04-26 07:32:20 +02:00
|
|
|
h, _ := r.Find(req.Method, req.URL.Path, c)
|
2015-05-30 02:20:13 +02:00
|
|
|
c.reset(req, w, r.echo)
|
2015-07-24 21:03:36 +02:00
|
|
|
if err := h(c); err != nil {
|
|
|
|
r.echo.httpErrorHandler(err, c)
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
2015-04-09 07:23:47 +02:00
|
|
|
r.echo.pool.Put(c)
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|