rename NewPatRouter to NewRouter

master
kevin 4 years ago
parent dfe6e88529
commit 737cd4751a

@ -57,7 +57,7 @@ func (s *engine) SetUnsignedCallback(callback handler.UnsignedCallback) {
} }
func (s *engine) Start() error { func (s *engine) Start() error {
return s.StartWithRouter(router.NewPatRouter()) return s.StartWithRouter(router.NewRouter())
} }
func (s *engine) StartWithRouter(router httpx.Router) error { func (s *engine) StartWithRouter(router httpx.Router) error {

@ -21,18 +21,18 @@ var (
ErrInvalidPath = errors.New("path must begin with '/'") ErrInvalidPath = errors.New("path must begin with '/'")
) )
type PatRouter struct { type patRouter struct {
trees map[string]*search.Tree trees map[string]*search.Tree
notFound http.Handler notFound http.Handler
} }
func NewPatRouter() httpx.Router { func NewRouter() httpx.Router {
return &PatRouter{ return &patRouter{
trees: make(map[string]*search.Tree), trees: make(map[string]*search.Tree),
} }
} }
func (pr *PatRouter) Handle(method, reqPath string, handler http.Handler) error { func (pr *patRouter) Handle(method, reqPath string, handler http.Handler) error {
if !validMethod(method) { if !validMethod(method) {
return ErrInvalidMethod return ErrInvalidMethod
} }
@ -51,7 +51,7 @@ func (pr *PatRouter) Handle(method, reqPath string, handler http.Handler) error
} }
} }
func (pr *PatRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (pr *patRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
reqPath := path.Clean(r.URL.Path) reqPath := path.Clean(r.URL.Path)
if tree, ok := pr.trees[r.Method]; ok { if tree, ok := pr.trees[r.Method]; ok {
if result, ok := tree.Search(reqPath); ok { if result, ok := tree.Search(reqPath); ok {
@ -71,11 +71,11 @@ func (pr *PatRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
func (pr *PatRouter) SetNotFoundHandler(handler http.Handler) { func (pr *patRouter) SetNotFoundHandler(handler http.Handler) {
pr.notFound = handler pr.notFound = handler
} }
func (pr *PatRouter) handleNotFound(w http.ResponseWriter, r *http.Request) { func (pr *patRouter) handleNotFound(w http.ResponseWriter, r *http.Request) {
if pr.notFound != nil { if pr.notFound != nil {
pr.notFound.ServeHTTP(w, r) pr.notFound.ServeHTTP(w, r)
} else { } else {
@ -83,7 +83,7 @@ func (pr *PatRouter) handleNotFound(w http.ResponseWriter, r *http.Request) {
} }
} }
func (pr *PatRouter) methodNotAllowed(method, path string) (string, bool) { func (pr *patRouter) methodNotAllowed(method, path string) (string, bool) {
var allows []string var allows []string
for treeMethod, tree := range pr.trees { for treeMethod, tree := range pr.trees {

@ -47,7 +47,7 @@ func TestPatRouterHandleErrors(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.method, func(t *testing.T) { t.Run(test.method, func(t *testing.T) {
router := NewPatRouter() router := NewRouter()
err := router.Handle(test.method, test.path, nil) err := router.Handle(test.method, test.path, nil)
assert.Error(t, ErrInvalidMethod, err) assert.Error(t, ErrInvalidMethod, err)
}) })
@ -56,7 +56,7 @@ func TestPatRouterHandleErrors(t *testing.T) {
func TestPatRouterNotFound(t *testing.T) { func TestPatRouterNotFound(t *testing.T) {
var notFound bool var notFound bool
router := NewPatRouter() router := NewRouter()
router.SetNotFoundHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { router.SetNotFoundHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
notFound = true notFound = true
})) }))
@ -87,7 +87,7 @@ func TestPatRouter(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.method+":"+test.path, func(t *testing.T) { t.Run(test.method+":"+test.path, func(t *testing.T) {
routed := false routed := false
router := NewPatRouter() router := NewRouter()
err := router.Handle(test.method, "/a/:b", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err := router.Handle(test.method, "/a/:b", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
routed = true routed = true
assert.Equal(t, 1, len(context.Vars(r))) assert.Equal(t, 1, len(context.Vars(r)))
@ -125,7 +125,7 @@ func TestParseSlice(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set("Content-Type", "application/x-www-form-urlencoded") r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rt := NewPatRouter() rt := NewRouter()
err = rt.Handle(http.MethodPost, "/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err = rt.Handle(http.MethodPost, "/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
Names []string `form:"names"` Names []string `form:"names"`
@ -149,7 +149,7 @@ func TestParseJsonPost(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, httpx.ApplicationJson) r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(
w http.ResponseWriter, r *http.Request) { w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -181,7 +181,7 @@ func TestParseJsonPostWithIntSlice(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, httpx.ApplicationJson) r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(
w http.ResponseWriter, r *http.Request) { w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -209,7 +209,7 @@ func TestParseJsonPostError(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, httpx.ApplicationJson) r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -237,7 +237,7 @@ func TestParseJsonPostInvalidRequest(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, httpx.ApplicationJson) r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/", http.HandlerFunc( err = router.Handle(http.MethodPost, "/", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -259,7 +259,7 @@ func TestParseJsonPostRequired(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, httpx.ApplicationJson) r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -282,7 +282,7 @@ func TestParsePath(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017", nil) r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017", nil)
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -307,7 +307,7 @@ func TestParsePathRequired(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin", nil) r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin", nil)
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -328,7 +328,7 @@ func TestParseQuery(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil) r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -353,7 +353,7 @@ func TestParseQueryRequired(t *testing.T) {
r, err := http.NewRequest(http.MethodPost, "http://hello.com/kevin/2017?nickname=whatever", nil) r, err := http.NewRequest(http.MethodPost, "http://hello.com/kevin/2017?nickname=whatever", nil)
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
Nickname string `form:"nickname"` Nickname string `form:"nickname"`
@ -373,7 +373,7 @@ func TestParseOptional(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil) r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -414,7 +414,7 @@ func TestParseNestedInRequestEmpty(t *testing.T) {
} }
) )
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
var v WrappedRequest var v WrappedRequest
@ -453,7 +453,7 @@ func TestParsePtrInRequest(t *testing.T) {
} }
) )
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
var v WrappedRequest var v WrappedRequest
@ -484,7 +484,7 @@ func TestParsePtrInRequestEmpty(t *testing.T) {
} }
) )
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/kevin", http.HandlerFunc( err = router.Handle(http.MethodPost, "/kevin", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
var v WrappedRequest var v WrappedRequest
@ -501,7 +501,7 @@ func TestParseQueryOptional(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil) r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -526,7 +526,7 @@ func TestParse(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil) r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -564,7 +564,7 @@ func TestParseWrappedRequest(t *testing.T) {
} }
) )
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
var v WrappedRequest var v WrappedRequest
@ -596,7 +596,7 @@ func TestParseWrappedGetRequestWithJsonHeader(t *testing.T) {
} }
) )
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
var v WrappedRequest var v WrappedRequest
@ -629,7 +629,7 @@ func TestParseWrappedHeadRequestWithJsonHeader(t *testing.T) {
} }
) )
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodHead, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodHead, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
var v WrappedRequest var v WrappedRequest
@ -661,7 +661,7 @@ func TestParseWrappedRequestPtr(t *testing.T) {
} }
) )
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
var v WrappedRequest var v WrappedRequest
@ -684,7 +684,7 @@ func TestParseWithAll(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, httpx.ApplicationJson) r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
Name string `path:"name"` Name string `path:"name"`
@ -715,7 +715,7 @@ func TestParseWithAllUtf8(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8) r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -746,7 +746,7 @@ func TestParseWithMissingForm(t *testing.T) {
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`)) bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -773,7 +773,7 @@ func TestParseWithMissingAllForms(t *testing.T) {
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`)) bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -799,7 +799,7 @@ func TestParseWithMissingJson(t *testing.T) {
bytes.NewBufferString(`{"location": "shanghai"}`)) bytes.NewBufferString(`{"location": "shanghai"}`))
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -825,7 +825,7 @@ func TestParseWithMissingAllJsons(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil) r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=200000", nil)
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -852,7 +852,7 @@ func TestParseWithMissingPath(t *testing.T) {
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`)) bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -879,7 +879,7 @@ func TestParseWithMissingAllPaths(t *testing.T) {
bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`)) bytes.NewBufferString(`{"location": "shanghai", "time": 20170912}`))
assert.Nil(t, err) assert.Nil(t, err)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -906,7 +906,7 @@ func TestParseGetWithContentLengthHeader(t *testing.T) {
r.Header.Set(httpx.ContentType, httpx.ApplicationJson) r.Header.Set(httpx.ContentType, httpx.ApplicationJson)
r.Header.Set(contentLength, "1024") r.Header.Set(contentLength, "1024")
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -933,7 +933,7 @@ func TestParseJsonPostWithTypeMismatch(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8) r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -959,7 +959,7 @@ func TestParseJsonPostWithInt2String(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
r.Header.Set(httpx.ContentType, applicationJsonWithUtf8) r.Header.Set(httpx.ContentType, applicationJsonWithUtf8)
router := NewPatRouter() router := NewRouter()
err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc( err = router.Handle(http.MethodPost, "/:name/:year", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
v := struct { v := struct {
@ -980,7 +980,7 @@ func TestParseJsonPostWithInt2String(t *testing.T) {
func BenchmarkPatRouter(b *testing.B) { func BenchmarkPatRouter(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
router := NewPatRouter() router := NewRouter()
router.Handle(http.MethodGet, "/api/:user/:name", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { router.Handle(http.MethodGet, "/api/:user/:name", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
})) }))
w := &mockedResponseWriter{} w := &mockedResponseWriter{}

@ -14,7 +14,7 @@ import (
func TestWithMiddleware(t *testing.T) { func TestWithMiddleware(t *testing.T) {
m := make(map[string]string) m := make(map[string]string)
router := router.NewPatRouter() router := router.NewRouter()
handler := func(w http.ResponseWriter, r *http.Request) { handler := func(w http.ResponseWriter, r *http.Request) {
var v struct { var v struct {
Nickname string `form:"nickname"` Nickname string `form:"nickname"`
@ -71,7 +71,7 @@ func TestWithMiddleware(t *testing.T) {
func TestMultiMiddleware(t *testing.T) { func TestMultiMiddleware(t *testing.T) {
m := make(map[string]string) m := make(map[string]string)
router := router.NewPatRouter() router := router.NewRouter()
handler := func(w http.ResponseWriter, r *http.Request) { handler := func(w http.ResponseWriter, r *http.Request) {
var v struct { var v struct {
Nickname string `form:"nickname"` Nickname string `form:"nickname"`

Loading…
Cancel
Save