| "log" | "log" | ||||
| "net/http" | "net/http" | ||||
| "path/filepath" | "path/filepath" | ||||
| "reflect" | |||||
| "runtime" | "runtime" | ||||
| "strings" | |||||
| "sync" | "sync" | ||||
| "time" | "time" | ||||
| // register adds the http.Handler/http.HandleFunc into Gorilla mux. | // register adds the http.Handler/http.HandleFunc into Gorilla mux. | ||||
| func (self *server) register(pattern string, handler interface{}, methods ...string) { | 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. | // 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) { | switch H := handler.(type) { | ||||
| case http.Handler: | case http.Handler: |
| }) | }) | ||||
| } | } | ||||
| 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) { | func TestGET(t *testing.T) { | ||||
| app := New() | app := New() | ||||
| app.GET("/", func(w http.ResponseWriter, r *http.Request) { | app.GET("/", func(w http.ResponseWriter, r *http.Request) { |