Преглед изворни кода

Named router fixed + test coverage

tags/v0.9.0
jimzhan пре 9 година
родитељ
комит
aa2b4405ef
2 измењених фајлова са 17 додато и 2 уклоњено
  1. +3
    -2
      server.go
  2. +14
    -0
      server_test.go

+ 3
- 2
server.go Прегледај датотеку

@@ -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:

+ 14
- 0
server_test.go Прегледај датотеку

@@ -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) {

Loading…
Откажи
Сачувај