@@ -6,8 +6,8 @@ import ( | |||
"log" | |||
"net/http" | |||
"path/filepath" | |||
"reflect" | |||
"runtime" | |||
"strings" | |||
"sync" | |||
"time" | |||
@@ -69,8 +69,9 @@ func (self *server) build() http.Handler { | |||
// register adds the http.Handler/http.HandleFunc into Gorilla mux. | |||
func (self *server) register(pattern string, handler interface{}, methods ...string) { | |||
var name = strings.Join(methods, "|") + ":" + pattern | |||
// finds the full function name (with package) as its mappings. | |||
var name = runtime.FuncForPC(reflect.ValueOf(handler).Pointer()).Name() | |||
//var name = runtime.FuncForPC(reflect.ValueOf(handler).Pointer()).Name() | |||
switch H := handler.(type) { | |||
case http.Handler: |
@@ -106,6 +106,20 @@ func TestAny(t *testing.T) { | |||
}) | |||
} | |||
func TestName(t *testing.T) { | |||
Convey("rex.Name", t, func() { | |||
app := New() | |||
app.GET("/login", func(w http.ResponseWriter, r *http.Request) { | |||
w.WriteHeader(http.StatusOK) | |||
}) | |||
request, _ := http.NewRequest("GET", "/login", nil) | |||
response := httptest.NewRecorder() | |||
app.ServeHTTP(response, request) | |||
So(app.Name(request), ShouldEqual, "GET:/login") | |||
}) | |||
} | |||
func TestGET(t *testing.T) { | |||
app := New() | |||
app.GET("/", func(w http.ResponseWriter, r *http.Request) { |