4786fb09 by astaxie

beego:fix typo NewControllerRegister

1 parent fdb5672b
...@@ -27,7 +27,7 @@ type App struct { ...@@ -27,7 +27,7 @@ type App struct {
27 27
28 // NewApp returns a new beego application. 28 // NewApp returns a new beego application.
29 func NewApp() *App { 29 func NewApp() *App {
30 cr := NewControllerRegistor() 30 cr := NewControllerRegister()
31 app := &App{Handlers: cr, Server: &http.Server{}} 31 app := &App{Handlers: cr, Server: &http.Server{}}
32 return app 32 return app
33 } 33 }
......
...@@ -21,7 +21,7 @@ var FilterUser = func(ctx *context.Context) { ...@@ -21,7 +21,7 @@ var FilterUser = func(ctx *context.Context) {
21 func TestFilter(t *testing.T) { 21 func TestFilter(t *testing.T) {
22 r, _ := http.NewRequest("GET", "/person/asta/Xie", nil) 22 r, _ := http.NewRequest("GET", "/person/asta/Xie", nil)
23 w := httptest.NewRecorder() 23 w := httptest.NewRecorder()
24 handler := NewControllerRegistor() 24 handler := NewControllerRegister()
25 handler.InsertFilter("/person/:last/:first", BeforeRouter, FilterUser) 25 handler.InsertFilter("/person/:last/:first", BeforeRouter, FilterUser)
26 handler.Add("/person/:last/:first", &TestController{}) 26 handler.Add("/person/:last/:first", &TestController{})
27 handler.ServeHTTP(w, r) 27 handler.ServeHTTP(w, r)
...@@ -40,7 +40,7 @@ var FilterAdminUser = func(ctx *context.Context) { ...@@ -40,7 +40,7 @@ var FilterAdminUser = func(ctx *context.Context) {
40 func TestPatternTwo(t *testing.T) { 40 func TestPatternTwo(t *testing.T) {
41 r, _ := http.NewRequest("GET", "/admin/", nil) 41 r, _ := http.NewRequest("GET", "/admin/", nil)
42 w := httptest.NewRecorder() 42 w := httptest.NewRecorder()
43 handler := NewControllerRegistor() 43 handler := NewControllerRegister()
44 handler.InsertFilter("/admin/?:all", BeforeRouter, FilterAdminUser) 44 handler.InsertFilter("/admin/?:all", BeforeRouter, FilterAdminUser)
45 handler.ServeHTTP(w, r) 45 handler.ServeHTTP(w, r)
46 if w.Body.String() != "i am admin" { 46 if w.Body.String() != "i am admin" {
...@@ -51,7 +51,7 @@ func TestPatternTwo(t *testing.T) { ...@@ -51,7 +51,7 @@ func TestPatternTwo(t *testing.T) {
51 func TestPatternThree(t *testing.T) { 51 func TestPatternThree(t *testing.T) {
52 r, _ := http.NewRequest("GET", "/admin/astaxie", nil) 52 r, _ := http.NewRequest("GET", "/admin/astaxie", nil)
53 w := httptest.NewRecorder() 53 w := httptest.NewRecorder()
54 handler := NewControllerRegistor() 54 handler := NewControllerRegister()
55 handler.InsertFilter("/admin/:all", BeforeRouter, FilterAdminUser) 55 handler.InsertFilter("/admin/:all", BeforeRouter, FilterAdminUser)
56 handler.ServeHTTP(w, r) 56 handler.ServeHTTP(w, r)
57 if w.Body.String() != "i am admin" { 57 if w.Body.String() != "i am admin" {
......
...@@ -31,7 +31,7 @@ func TestFlashHeader(t *testing.T) { ...@@ -31,7 +31,7 @@ func TestFlashHeader(t *testing.T) {
31 w := httptest.NewRecorder() 31 w := httptest.NewRecorder()
32 32
33 // setup the handler 33 // setup the handler
34 handler := NewControllerRegistor() 34 handler := NewControllerRegister()
35 handler.Add("/", &TestFlashController{}, "get:TestWriteFlash") 35 handler.Add("/", &TestFlashController{}, "get:TestWriteFlash")
36 handler.ServeHTTP(w, r) 36 handler.ServeHTTP(w, r)
37 37
......
...@@ -26,7 +26,7 @@ type Namespace struct { ...@@ -26,7 +26,7 @@ type Namespace struct {
26 func NewNamespace(prefix string, params ...innnerNamespace) *Namespace { 26 func NewNamespace(prefix string, params ...innnerNamespace) *Namespace {
27 ns := &Namespace{ 27 ns := &Namespace{
28 prefix: prefix, 28 prefix: prefix,
29 handlers: NewControllerRegistor(), 29 handlers: NewControllerRegister(),
30 } 30 }
31 for _, p := range params { 31 for _, p := range params {
32 p(ns) 32 p(ns)
......
...@@ -75,8 +75,8 @@ type ControllerRegistor struct { ...@@ -75,8 +75,8 @@ type ControllerRegistor struct {
75 filters map[int][]*FilterRouter 75 filters map[int][]*FilterRouter
76 } 76 }
77 77
78 // NewControllerRegistor returns a new ControllerRegistor. 78 // NewControllerRegister returns a new ControllerRegistor.
79 func NewControllerRegistor() *ControllerRegistor { 79 func NewControllerRegister() *ControllerRegistor {
80 return &ControllerRegistor{ 80 return &ControllerRegistor{
81 routers: make(map[string]*Tree), 81 routers: make(map[string]*Tree),
82 filters: make(map[int][]*FilterRouter), 82 filters: make(map[int][]*FilterRouter),
......
...@@ -72,7 +72,7 @@ func (this *JsonController) Get() { ...@@ -72,7 +72,7 @@ func (this *JsonController) Get() {
72 } 72 }
73 73
74 func TestUrlFor(t *testing.T) { 74 func TestUrlFor(t *testing.T) {
75 handler := NewControllerRegistor() 75 handler := NewControllerRegister()
76 handler.Add("/api/list", &TestController{}, "*:List") 76 handler.Add("/api/list", &TestController{}, "*:List")
77 handler.Add("/person/:last/:first", &TestController{}) 77 handler.Add("/person/:last/:first", &TestController{})
78 handler.AddAuto(&TestController{}) 78 handler.AddAuto(&TestController{})
...@@ -95,7 +95,7 @@ func TestUserFunc(t *testing.T) { ...@@ -95,7 +95,7 @@ func TestUserFunc(t *testing.T) {
95 r, _ := http.NewRequest("GET", "/api/list", nil) 95 r, _ := http.NewRequest("GET", "/api/list", nil)
96 w := httptest.NewRecorder() 96 w := httptest.NewRecorder()
97 97
98 handler := NewControllerRegistor() 98 handler := NewControllerRegister()
99 handler.Add("/api/list", &TestController{}, "*:List") 99 handler.Add("/api/list", &TestController{}, "*:List")
100 handler.ServeHTTP(w, r) 100 handler.ServeHTTP(w, r)
101 if w.Body.String() != "i am list" { 101 if w.Body.String() != "i am list" {
...@@ -107,7 +107,7 @@ func TestPostFunc(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestPostFunc(t *testing.T) {
107 r, _ := http.NewRequest("POST", "/astaxie", nil) 107 r, _ := http.NewRequest("POST", "/astaxie", nil)
108 w := httptest.NewRecorder() 108 w := httptest.NewRecorder()
109 109
110 handler := NewControllerRegistor() 110 handler := NewControllerRegister()
111 handler.Add("/:name", &TestController{}) 111 handler.Add("/:name", &TestController{})
112 handler.ServeHTTP(w, r) 112 handler.ServeHTTP(w, r)
113 if w.Body.String() != "astaxie" { 113 if w.Body.String() != "astaxie" {
...@@ -119,7 +119,7 @@ func TestAutoFunc(t *testing.T) { ...@@ -119,7 +119,7 @@ func TestAutoFunc(t *testing.T) {
119 r, _ := http.NewRequest("GET", "/test/list", nil) 119 r, _ := http.NewRequest("GET", "/test/list", nil)
120 w := httptest.NewRecorder() 120 w := httptest.NewRecorder()
121 121
122 handler := NewControllerRegistor() 122 handler := NewControllerRegister()
123 handler.AddAuto(&TestController{}) 123 handler.AddAuto(&TestController{})
124 handler.ServeHTTP(w, r) 124 handler.ServeHTTP(w, r)
125 if w.Body.String() != "i am list" { 125 if w.Body.String() != "i am list" {
...@@ -131,7 +131,7 @@ func TestAutoFuncParams(t *testing.T) { ...@@ -131,7 +131,7 @@ func TestAutoFuncParams(t *testing.T) {
131 r, _ := http.NewRequest("GET", "/test/params/2009/11/12", nil) 131 r, _ := http.NewRequest("GET", "/test/params/2009/11/12", nil)
132 w := httptest.NewRecorder() 132 w := httptest.NewRecorder()
133 133
134 handler := NewControllerRegistor() 134 handler := NewControllerRegister()
135 handler.AddAuto(&TestController{}) 135 handler.AddAuto(&TestController{})
136 handler.ServeHTTP(w, r) 136 handler.ServeHTTP(w, r)
137 if w.Body.String() != "20091112" { 137 if w.Body.String() != "20091112" {
...@@ -143,7 +143,7 @@ func TestAutoExtFunc(t *testing.T) { ...@@ -143,7 +143,7 @@ func TestAutoExtFunc(t *testing.T) {
143 r, _ := http.NewRequest("GET", "/test/myext.json", nil) 143 r, _ := http.NewRequest("GET", "/test/myext.json", nil)
144 w := httptest.NewRecorder() 144 w := httptest.NewRecorder()
145 145
146 handler := NewControllerRegistor() 146 handler := NewControllerRegister()
147 handler.AddAuto(&TestController{}) 147 handler.AddAuto(&TestController{})
148 handler.ServeHTTP(w, r) 148 handler.ServeHTTP(w, r)
149 if w.Body.String() != "json" { 149 if w.Body.String() != "json" {
...@@ -156,7 +156,7 @@ func TestRouteOk(t *testing.T) { ...@@ -156,7 +156,7 @@ func TestRouteOk(t *testing.T) {
156 r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil) 156 r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil)
157 w := httptest.NewRecorder() 157 w := httptest.NewRecorder()
158 158
159 handler := NewControllerRegistor() 159 handler := NewControllerRegister()
160 handler.Add("/person/:last/:first", &TestController{}, "get:GetParams") 160 handler.Add("/person/:last/:first", &TestController{}, "get:GetParams")
161 handler.ServeHTTP(w, r) 161 handler.ServeHTTP(w, r)
162 body := w.Body.String() 162 body := w.Body.String()
...@@ -170,7 +170,7 @@ func TestManyRoute(t *testing.T) { ...@@ -170,7 +170,7 @@ func TestManyRoute(t *testing.T) {
170 r, _ := http.NewRequest("GET", "/beego32-12.html", nil) 170 r, _ := http.NewRequest("GET", "/beego32-12.html", nil)
171 w := httptest.NewRecorder() 171 w := httptest.NewRecorder()
172 172
173 handler := NewControllerRegistor() 173 handler := NewControllerRegister()
174 handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{}, "get:GetManyRouter") 174 handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{}, "get:GetManyRouter")
175 handler.ServeHTTP(w, r) 175 handler.ServeHTTP(w, r)
176 176
...@@ -185,7 +185,7 @@ func TestNotFound(t *testing.T) { ...@@ -185,7 +185,7 @@ func TestNotFound(t *testing.T) {
185 r, _ := http.NewRequest("GET", "/", nil) 185 r, _ := http.NewRequest("GET", "/", nil)
186 w := httptest.NewRecorder() 186 w := httptest.NewRecorder()
187 187
188 handler := NewControllerRegistor() 188 handler := NewControllerRegister()
189 handler.ServeHTTP(w, r) 189 handler.ServeHTTP(w, r)
190 190
191 if w.Code != http.StatusNotFound { 191 if w.Code != http.StatusNotFound {
...@@ -199,7 +199,7 @@ func TestStatic(t *testing.T) { ...@@ -199,7 +199,7 @@ func TestStatic(t *testing.T) {
199 r, _ := http.NewRequest("GET", "/static/js/jquery.js", nil) 199 r, _ := http.NewRequest("GET", "/static/js/jquery.js", nil)
200 w := httptest.NewRecorder() 200 w := httptest.NewRecorder()
201 201
202 handler := NewControllerRegistor() 202 handler := NewControllerRegister()
203 handler.ServeHTTP(w, r) 203 handler.ServeHTTP(w, r)
204 204
205 if w.Code != 404 { 205 if w.Code != 404 {
...@@ -211,7 +211,7 @@ func TestPrepare(t *testing.T) { ...@@ -211,7 +211,7 @@ func TestPrepare(t *testing.T) {
211 r, _ := http.NewRequest("GET", "/json/list", nil) 211 r, _ := http.NewRequest("GET", "/json/list", nil)
212 w := httptest.NewRecorder() 212 w := httptest.NewRecorder()
213 213
214 handler := NewControllerRegistor() 214 handler := NewControllerRegister()
215 handler.Add("/json/list", &JsonController{}) 215 handler.Add("/json/list", &JsonController{})
216 handler.ServeHTTP(w, r) 216 handler.ServeHTTP(w, r)
217 if w.Body.String() != `"prepare"` { 217 if w.Body.String() != `"prepare"` {
...@@ -223,7 +223,7 @@ func TestAutoPrefix(t *testing.T) { ...@@ -223,7 +223,7 @@ func TestAutoPrefix(t *testing.T) {
223 r, _ := http.NewRequest("GET", "/admin/test/list", nil) 223 r, _ := http.NewRequest("GET", "/admin/test/list", nil)
224 w := httptest.NewRecorder() 224 w := httptest.NewRecorder()
225 225
226 handler := NewControllerRegistor() 226 handler := NewControllerRegister()
227 handler.AddAutoPrefix("/admin", &TestController{}) 227 handler.AddAutoPrefix("/admin", &TestController{})
228 handler.ServeHTTP(w, r) 228 handler.ServeHTTP(w, r)
229 if w.Body.String() != "i am list" { 229 if w.Body.String() != "i am list" {
...@@ -235,7 +235,7 @@ func TestRouterGet(t *testing.T) { ...@@ -235,7 +235,7 @@ func TestRouterGet(t *testing.T) {
235 r, _ := http.NewRequest("GET", "/user", nil) 235 r, _ := http.NewRequest("GET", "/user", nil)
236 w := httptest.NewRecorder() 236 w := httptest.NewRecorder()
237 237
238 handler := NewControllerRegistor() 238 handler := NewControllerRegister()
239 handler.Get("/user", func(ctx *context.Context) { 239 handler.Get("/user", func(ctx *context.Context) {
240 ctx.Output.Body([]byte("Get userlist")) 240 ctx.Output.Body([]byte("Get userlist"))
241 }) 241 })
...@@ -249,7 +249,7 @@ func TestRouterPost(t *testing.T) { ...@@ -249,7 +249,7 @@ func TestRouterPost(t *testing.T) {
249 r, _ := http.NewRequest("POST", "/user/123", nil) 249 r, _ := http.NewRequest("POST", "/user/123", nil)
250 w := httptest.NewRecorder() 250 w := httptest.NewRecorder()
251 251
252 handler := NewControllerRegistor() 252 handler := NewControllerRegister()
253 handler.Post("/user/:id", func(ctx *context.Context) { 253 handler.Post("/user/:id", func(ctx *context.Context) {
254 ctx.Output.Body([]byte(ctx.Input.Param(":id"))) 254 ctx.Output.Body([]byte(ctx.Input.Param(":id")))
255 }) 255 })
...@@ -267,7 +267,7 @@ func TestRouterHandler(t *testing.T) { ...@@ -267,7 +267,7 @@ func TestRouterHandler(t *testing.T) {
267 r, _ := http.NewRequest("POST", "/sayhi", nil) 267 r, _ := http.NewRequest("POST", "/sayhi", nil)
268 w := httptest.NewRecorder() 268 w := httptest.NewRecorder()
269 269
270 handler := NewControllerRegistor() 270 handler := NewControllerRegister()
271 handler.Handler("/sayhi", http.HandlerFunc(sayhello)) 271 handler.Handler("/sayhi", http.HandlerFunc(sayhello))
272 handler.ServeHTTP(w, r) 272 handler.ServeHTTP(w, r)
273 if w.Body.String() != "sayhello" { 273 if w.Body.String() != "sayhello" {
...@@ -292,7 +292,7 @@ func (a *AdminController) Get() { ...@@ -292,7 +292,7 @@ func (a *AdminController) Get() {
292 } 292 }
293 293
294 func TestRouterFunc(t *testing.T) { 294 func TestRouterFunc(t *testing.T) {
295 mux := NewControllerRegistor() 295 mux := NewControllerRegister()
296 mux.Get("/action", beegoFilterFunc) 296 mux.Get("/action", beegoFilterFunc)
297 mux.Post("/action", beegoFilterFunc) 297 mux.Post("/action", beegoFilterFunc)
298 rw, r := testRequest("GET", "/action") 298 rw, r := testRequest("GET", "/action")
...@@ -303,7 +303,7 @@ func TestRouterFunc(t *testing.T) { ...@@ -303,7 +303,7 @@ func TestRouterFunc(t *testing.T) {
303 } 303 }
304 304
305 func BenchmarkFunc(b *testing.B) { 305 func BenchmarkFunc(b *testing.B) {
306 mux := NewControllerRegistor() 306 mux := NewControllerRegister()
307 mux.Get("/action", beegoFilterFunc) 307 mux.Get("/action", beegoFilterFunc)
308 rw, r := testRequest("GET", "/action") 308 rw, r := testRequest("GET", "/action")
309 b.ResetTimer() 309 b.ResetTimer()
...@@ -313,7 +313,7 @@ func BenchmarkFunc(b *testing.B) { ...@@ -313,7 +313,7 @@ func BenchmarkFunc(b *testing.B) {
313 } 313 }
314 314
315 func BenchmarkController(b *testing.B) { 315 func BenchmarkController(b *testing.B) {
316 mux := NewControllerRegistor() 316 mux := NewControllerRegister()
317 mux.Add("/action", &AdminController{}) 317 mux.Add("/action", &AdminController{})
318 rw, r := testRequest("GET", "/action") 318 rw, r := testRequest("GET", "/action")
319 b.ResetTimer() 319 b.ResetTimer()
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!