1
0
mirror of https://github.com/labstack/echo.git synced 2025-12-21 23:57:40 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-04-24 07:44:30 -07:00
parent d9185ddf5c
commit 1033df5ac0
3 changed files with 157 additions and 26 deletions

10
echo.go
View File

@@ -4,10 +4,11 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"reflect"
"runtime"
"strings"
"sync"
@@ -111,7 +112,6 @@ func New() (e *Echo) {
Response: &response{},
params: make(Params, e.maxParam),
store: make(store),
echo: e, // TODO: Do we need this?
}
}
@@ -237,7 +237,8 @@ func (e *Echo) URI(h Handler, params ...string) string {
uri := new(bytes.Buffer)
lp := len(params)
n := 0
if path, ok := e.uris[fmt.Sprintf("%v", h)]; ok {
key := runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name()
if path, ok := e.uris[key]; ok {
for i, l := 0, len(path); i < l; i++ {
if path[i] == ':' && n < lp {
for ; i < l && path[i] != '/'; i++ {
@@ -259,7 +260,8 @@ func (e *Echo) URL(h Handler, params ...string) string {
}
func (e *Echo) add(method, path string, h Handler) {
e.uris[fmt.Sprintf("%v", h)] = path
key := runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name()
e.uris[key] = path
e.Router.Add(method, e.prefix+path, wrapH(h), e)
}