@@ -42,9 +42,10 @@ func main() {
42
42
43
43
r.GET (" /" , func (c router.Context ) error {
44
44
// c.Request() is original http.Request
45
- // c.Response() is original http.ResponseWriter
45
+ // c.Response() is original http.ResponseWriter
46
46
return c.Text (http.StatusOK , " Hello from GoLobby Router!" )
47
47
})
48
+
48
49
r.PUT (" /products/:id" , func (c router.Context ) error {
49
50
return c.Text (http.StatusOK , " Update product with ID: " +c.Parameter (" id" ))
50
51
})
@@ -153,13 +154,13 @@ func main() {
153
154
154
155
r.GET (" /links" , func (c router.Context ) error {
155
156
return c.JSON (http.StatusOK , response.M {
156
- // URL: /
157
- " home" : c.URL (" home" , nil ),
158
- // URL: /posts/1
159
- " post-1" : c.URL (" post" , map [string ]string {" id" : " 1" }),
160
- // URL: /posts/2
161
- " post-2" : c.URL (" post" , map [string ]string {" id" : " 2" }),
162
- })
157
+ // "/"
158
+ " home" : c.URL (" home" , nil ),
159
+ // " /posts/1"
160
+ " post-1" : c.URL (" post" , map [string ]string {" id" : " 1" }),
161
+ // " /posts/2"
162
+ " post-2" : c.URL (" post" , map [string ]string {" id" : " 2" }),
163
+ })
163
164
})
164
165
165
166
log.Fatalln (r.Start (" :8000" ))
@@ -168,7 +169,7 @@ func main() {
168
169
169
170
### Responses
170
171
171
- The router comes with ` Empty ` , ` Redirect ` , ` Text ` , ` HTML ` , ` JSON ` , ` PrettyJSON ` , ` XML ` , and ` PrettyXML ` responses out of the box.
172
+ The router comes with ` Empty ` , ` Redirect ` , ` Text ` , ` HTML ` , ` JSON ` , ` PrettyJSON ` , ` XML ` , ` PrettyXML ` , and ` Bytes ` responses out of the box.
172
173
The examples below demonstrate how to use built-in and custom responses.
173
174
174
175
``` go
@@ -293,7 +294,7 @@ func main() {
293
294
294
295
r.WithMiddleware (AdminMiddleware, func () {
295
296
r.GET (" /admin/users" , UsersHandler)
296
- r.GET (" /admin/products" , ProductsHandler)
297
+ r.GET (" /admin/products" , ProductsHandler)
297
298
})
298
299
299
300
log.Fatalln (r.Start (" :8000" ))
@@ -343,7 +344,7 @@ func main() {
343
344
344
345
r.Group (" /blog" , []router.Middleware {Middleware1, Middleware2}, func () {
345
346
r.GET (" /posts" , PostsHandler)
346
- r.GET (" /posts/:id/comments" , CommentsHandler)
347
+ r.GET (" /posts/:id/comments" , CommentsHandler)
347
348
})
348
349
349
350
log.Fatalln (r.Start (" :8000" ))
@@ -475,7 +476,7 @@ func main() {
475
476
return c.HTML (500 , " <p>Something went wrong</p>" )
476
477
}
477
478
478
- // No error will raise to the router base handler
479
+ // No error will raise to the router base handler
479
480
return nil
480
481
}
481
482
})
0 commit comments