Skip to content

Commit

Permalink
Merge branch 'master' of github.com:golobby/router
Browse files Browse the repository at this point in the history
  • Loading branch information
miladrahimi committed Mar 4, 2022
2 parents 25aba35 + 90e05d4 commit 0d3cb52
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ It's built on top of the Go HTTP package and uses radix tree to provide the foll
* Middleware
* HTTP Responses (such as JSON, XML, Text, Empty, and Redirect)
* No footprint!
* Zero-dependency!

## Documentation
### Required Go Version
Expand Down Expand Up @@ -154,12 +155,9 @@ func main() {

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

Expand Down Expand Up @@ -256,12 +254,11 @@ func main() {
r := router.New()

r.WithPrefix("/blog", func() {
r.GET("/posts", PostsHandler)
r.GET("/posts/:id", PostHandler)

r.WithPrefix("/pages", func() {
r.GET("/about", AboutHandler)
r.GET("/contact", ContactHandler)
r.GET("/posts", PostsHandler) // "/blog/posts"
r.GET("/posts/:id", PostHandler) // "/blog/posts/:id"
r.WithPrefix("/pages", func() {
r.GET("/about", AboutHandler) // "/blog/pages/about"
r.GET("/contact", ContactHandler) // "/blog/pages/contact"
})
})

Expand Down Expand Up @@ -433,6 +430,7 @@ import (
func main() {
r := router.New()

// Custom (HTML) Not Found Handler
r.SetNotFoundHandler(func(c router.Context) error {
return c.HTML(404, "<p>404 Not Found</p>")
})
Expand Down

0 comments on commit 0d3cb52

Please sign in to comment.