December 2017
Intermediate to advanced
316 pages
6h 58m
English
In simple words, a reverse-mapping URL is just getting the URL for an API resource. Reverse-mapping is quite useful when we need to share links to our web application or API. But in order to create a URL from the data, we should associate a Name with the Mux route:
r.HandlerFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler). Name("articleRoute")
Now, if we have data, we can form an URL:
url, err := r.Get("articleRoute").URL("category", "books", "id", "123")fmt.Printf(url.URL) // prints /articles/books/123
Gorilla Mux provides a lot of flexibility in creating custom routes. It also allows method chaining to add properties to a created route.
Read now
Unlock full access