Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
miladrahimi authored Mar 4, 2022
1 parent 40ec8e7 commit 18734b5
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ func main() {

r.GET("/", func(c router.Context) error {
// c.Request() is original http.Request
// c.Response() is original http.ResponseWriter
// c.Response() is original http.ResponseWriter
return c.Text(http.StatusOK, "Hello from GoLobby Router!")
})

r.PUT("/products/:id", func(c router.Context) error {
return c.Text(http.StatusOK, "Update product with ID: "+c.Parameter("id"))
})
Expand Down Expand Up @@ -153,13 +154,13 @@ func main() {

r.GET("/links", func(c router.Context) error {
return c.JSON(http.StatusOK, response.M{
// URL: /
"home": c.URL("home", nil),
// URL: /posts/1
"post-1": c.URL("post", map[string]string{"id": "1"}),
// URL: /posts/2
"post-2": c.URL("post", map[string]string{"id": "2"}),
})
// "/"
"home": c.URL("home", nil),
// "/posts/1"
"post-1": c.URL("post", map[string]string{"id": "1"}),
// "/posts/2"
"post-2": c.URL("post", map[string]string{"id": "2"}),
})
})

log.Fatalln(r.Start(":8000"))
Expand All @@ -168,7 +169,7 @@ func main() {

### Responses

The router comes with `Empty`, `Redirect`, `Text`, `HTML`, `JSON`, `PrettyJSON`, `XML`, and `PrettyXML` responses out of the box.
The router comes with `Empty`, `Redirect`, `Text`, `HTML`, `JSON`, `PrettyJSON`, `XML`, `PrettyXML`, and `Bytes` responses out of the box.
The examples below demonstrate how to use built-in and custom responses.

```go
Expand Down Expand Up @@ -293,7 +294,7 @@ func main() {

r.WithMiddleware(AdminMiddleware, func() {
r.GET("/admin/users", UsersHandler)
r.GET("/admin/products", ProductsHandler)
r.GET("/admin/products", ProductsHandler)
})

log.Fatalln(r.Start(":8000"))
Expand Down Expand Up @@ -343,7 +344,7 @@ func main() {

r.Group("/blog", []router.Middleware{Middleware1, Middleware2}, func() {
r.GET("/posts", PostsHandler)
r.GET("/posts/:id/comments", CommentsHandler)
r.GET("/posts/:id/comments", CommentsHandler)
})

log.Fatalln(r.Start(":8000"))
Expand Down Expand Up @@ -475,7 +476,7 @@ func main() {
return c.HTML(500, "<p>Something went wrong</p>")
}

// No error will raise to the router base handler
// No error will raise to the router base handler
return nil
}
})
Expand Down

0 comments on commit 18734b5

Please sign in to comment.