mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 20:10:56 +00:00
beego:fix typo NewControllerRegister
This commit is contained in:
parent
fdb5672b7a
commit
4786fb0948
2
app.go
2
app.go
@ -27,7 +27,7 @@ type App struct {
|
|||||||
|
|
||||||
// NewApp returns a new beego application.
|
// NewApp returns a new beego application.
|
||||||
func NewApp() *App {
|
func NewApp() *App {
|
||||||
cr := NewControllerRegistor()
|
cr := NewControllerRegister()
|
||||||
app := &App{Handlers: cr, Server: &http.Server{}}
|
app := &App{Handlers: cr, Server: &http.Server{}}
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ var FilterUser = func(ctx *context.Context) {
|
|||||||
func TestFilter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
r, _ := http.NewRequest("GET", "/person/asta/Xie", nil)
|
r, _ := http.NewRequest("GET", "/person/asta/Xie", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.InsertFilter("/person/:last/:first", BeforeRouter, FilterUser)
|
handler.InsertFilter("/person/:last/:first", BeforeRouter, FilterUser)
|
||||||
handler.Add("/person/:last/:first", &TestController{})
|
handler.Add("/person/:last/:first", &TestController{})
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
@ -40,7 +40,7 @@ var FilterAdminUser = func(ctx *context.Context) {
|
|||||||
func TestPatternTwo(t *testing.T) {
|
func TestPatternTwo(t *testing.T) {
|
||||||
r, _ := http.NewRequest("GET", "/admin/", nil)
|
r, _ := http.NewRequest("GET", "/admin/", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.InsertFilter("/admin/?:all", BeforeRouter, FilterAdminUser)
|
handler.InsertFilter("/admin/?:all", BeforeRouter, FilterAdminUser)
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "i am admin" {
|
if w.Body.String() != "i am admin" {
|
||||||
@ -51,7 +51,7 @@ func TestPatternTwo(t *testing.T) {
|
|||||||
func TestPatternThree(t *testing.T) {
|
func TestPatternThree(t *testing.T) {
|
||||||
r, _ := http.NewRequest("GET", "/admin/astaxie", nil)
|
r, _ := http.NewRequest("GET", "/admin/astaxie", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.InsertFilter("/admin/:all", BeforeRouter, FilterAdminUser)
|
handler.InsertFilter("/admin/:all", BeforeRouter, FilterAdminUser)
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "i am admin" {
|
if w.Body.String() != "i am admin" {
|
||||||
|
@ -31,7 +31,7 @@ func TestFlashHeader(t *testing.T) {
|
|||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
// setup the handler
|
// setup the handler
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/", &TestFlashController{}, "get:TestWriteFlash")
|
handler.Add("/", &TestFlashController{}, "get:TestWriteFlash")
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ type Namespace struct {
|
|||||||
func NewNamespace(prefix string, params ...innnerNamespace) *Namespace {
|
func NewNamespace(prefix string, params ...innnerNamespace) *Namespace {
|
||||||
ns := &Namespace{
|
ns := &Namespace{
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
handlers: NewControllerRegistor(),
|
handlers: NewControllerRegister(),
|
||||||
}
|
}
|
||||||
for _, p := range params {
|
for _, p := range params {
|
||||||
p(ns)
|
p(ns)
|
||||||
|
@ -75,8 +75,8 @@ type ControllerRegistor struct {
|
|||||||
filters map[int][]*FilterRouter
|
filters map[int][]*FilterRouter
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewControllerRegistor returns a new ControllerRegistor.
|
// NewControllerRegister returns a new ControllerRegistor.
|
||||||
func NewControllerRegistor() *ControllerRegistor {
|
func NewControllerRegister() *ControllerRegistor {
|
||||||
return &ControllerRegistor{
|
return &ControllerRegistor{
|
||||||
routers: make(map[string]*Tree),
|
routers: make(map[string]*Tree),
|
||||||
filters: make(map[int][]*FilterRouter),
|
filters: make(map[int][]*FilterRouter),
|
||||||
|
@ -72,7 +72,7 @@ func (this *JsonController) Get() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUrlFor(t *testing.T) {
|
func TestUrlFor(t *testing.T) {
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/api/list", &TestController{}, "*:List")
|
handler.Add("/api/list", &TestController{}, "*:List")
|
||||||
handler.Add("/person/:last/:first", &TestController{})
|
handler.Add("/person/:last/:first", &TestController{})
|
||||||
handler.AddAuto(&TestController{})
|
handler.AddAuto(&TestController{})
|
||||||
@ -95,7 +95,7 @@ func TestUserFunc(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/api/list", nil)
|
r, _ := http.NewRequest("GET", "/api/list", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/api/list", &TestController{}, "*:List")
|
handler.Add("/api/list", &TestController{}, "*:List")
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "i am list" {
|
if w.Body.String() != "i am list" {
|
||||||
@ -107,7 +107,7 @@ func TestPostFunc(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("POST", "/astaxie", nil)
|
r, _ := http.NewRequest("POST", "/astaxie", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/:name", &TestController{})
|
handler.Add("/:name", &TestController{})
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "astaxie" {
|
if w.Body.String() != "astaxie" {
|
||||||
@ -119,7 +119,7 @@ func TestAutoFunc(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/test/list", nil)
|
r, _ := http.NewRequest("GET", "/test/list", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.AddAuto(&TestController{})
|
handler.AddAuto(&TestController{})
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "i am list" {
|
if w.Body.String() != "i am list" {
|
||||||
@ -131,7 +131,7 @@ func TestAutoFuncParams(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/test/params/2009/11/12", nil)
|
r, _ := http.NewRequest("GET", "/test/params/2009/11/12", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.AddAuto(&TestController{})
|
handler.AddAuto(&TestController{})
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "20091112" {
|
if w.Body.String() != "20091112" {
|
||||||
@ -143,7 +143,7 @@ func TestAutoExtFunc(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/test/myext.json", nil)
|
r, _ := http.NewRequest("GET", "/test/myext.json", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.AddAuto(&TestController{})
|
handler.AddAuto(&TestController{})
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "json" {
|
if w.Body.String() != "json" {
|
||||||
@ -156,7 +156,7 @@ func TestRouteOk(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil)
|
r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/person/:last/:first", &TestController{}, "get:GetParams")
|
handler.Add("/person/:last/:first", &TestController{}, "get:GetParams")
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
body := w.Body.String()
|
body := w.Body.String()
|
||||||
@ -170,7 +170,7 @@ func TestManyRoute(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/beego32-12.html", nil)
|
r, _ := http.NewRequest("GET", "/beego32-12.html", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{}, "get:GetManyRouter")
|
handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{}, "get:GetManyRouter")
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ func TestNotFound(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/", nil)
|
r, _ := http.NewRequest("GET", "/", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
if w.Code != http.StatusNotFound {
|
||||||
@ -199,7 +199,7 @@ func TestStatic(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/static/js/jquery.js", nil)
|
r, _ := http.NewRequest("GET", "/static/js/jquery.js", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
|
|
||||||
if w.Code != 404 {
|
if w.Code != 404 {
|
||||||
@ -211,7 +211,7 @@ func TestPrepare(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/json/list", nil)
|
r, _ := http.NewRequest("GET", "/json/list", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/json/list", &JsonController{})
|
handler.Add("/json/list", &JsonController{})
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != `"prepare"` {
|
if w.Body.String() != `"prepare"` {
|
||||||
@ -223,7 +223,7 @@ func TestAutoPrefix(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/admin/test/list", nil)
|
r, _ := http.NewRequest("GET", "/admin/test/list", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.AddAutoPrefix("/admin", &TestController{})
|
handler.AddAutoPrefix("/admin", &TestController{})
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "i am list" {
|
if w.Body.String() != "i am list" {
|
||||||
@ -235,7 +235,7 @@ func TestRouterGet(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("GET", "/user", nil)
|
r, _ := http.NewRequest("GET", "/user", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Get("/user", func(ctx *context.Context) {
|
handler.Get("/user", func(ctx *context.Context) {
|
||||||
ctx.Output.Body([]byte("Get userlist"))
|
ctx.Output.Body([]byte("Get userlist"))
|
||||||
})
|
})
|
||||||
@ -249,7 +249,7 @@ func TestRouterPost(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("POST", "/user/123", nil)
|
r, _ := http.NewRequest("POST", "/user/123", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Post("/user/:id", func(ctx *context.Context) {
|
handler.Post("/user/:id", func(ctx *context.Context) {
|
||||||
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
||||||
})
|
})
|
||||||
@ -267,7 +267,7 @@ func TestRouterHandler(t *testing.T) {
|
|||||||
r, _ := http.NewRequest("POST", "/sayhi", nil)
|
r, _ := http.NewRequest("POST", "/sayhi", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegister()
|
||||||
handler.Handler("/sayhi", http.HandlerFunc(sayhello))
|
handler.Handler("/sayhi", http.HandlerFunc(sayhello))
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "sayhello" {
|
if w.Body.String() != "sayhello" {
|
||||||
@ -292,7 +292,7 @@ func (a *AdminController) Get() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterFunc(t *testing.T) {
|
func TestRouterFunc(t *testing.T) {
|
||||||
mux := NewControllerRegistor()
|
mux := NewControllerRegister()
|
||||||
mux.Get("/action", beegoFilterFunc)
|
mux.Get("/action", beegoFilterFunc)
|
||||||
mux.Post("/action", beegoFilterFunc)
|
mux.Post("/action", beegoFilterFunc)
|
||||||
rw, r := testRequest("GET", "/action")
|
rw, r := testRequest("GET", "/action")
|
||||||
@ -303,7 +303,7 @@ func TestRouterFunc(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkFunc(b *testing.B) {
|
func BenchmarkFunc(b *testing.B) {
|
||||||
mux := NewControllerRegistor()
|
mux := NewControllerRegister()
|
||||||
mux.Get("/action", beegoFilterFunc)
|
mux.Get("/action", beegoFilterFunc)
|
||||||
rw, r := testRequest("GET", "/action")
|
rw, r := testRequest("GET", "/action")
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
@ -313,7 +313,7 @@ func BenchmarkFunc(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkController(b *testing.B) {
|
func BenchmarkController(b *testing.B) {
|
||||||
mux := NewControllerRegistor()
|
mux := NewControllerRegister()
|
||||||
mux.Add("/action", &AdminController{})
|
mux.Add("/action", &AdminController{})
|
||||||
rw, r := testRequest("GET", "/action")
|
rw, r := testRequest("GET", "/action")
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
Loading…
Reference in New Issue
Block a user