1
votes

I'm new in development. Now trying to learn gorilla/mux router. The question is about reversed urls. In gorilla/mux I know we name them with .Name() method and access with .Url(). Could someone explain real use case of reserved URL's(Reverse mapping URL)? But a few hours of googling didn't help me to find any info about that why we even need them? Will be really thankfull if you could show some practical examples.

1
What is your definition of "reversed URLs"? - Emile Pels
reserved URL or Reverse mapping URL - Farhad Kocharli
Below section is from gorila/mux doc.why we need and when use it? Now let's see how to build registered URLs.Routes can be named.All routes that define a name can have their URLs built, or "reversed".We define a name calling Name() on a route.For example: r := mux.NewRouter() r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler). Name("article") To build a URL, get the route and call the URL() method, passing a sequence of key/value pairs for the route variables. For the previous route, we would do: url, err := r.Get("article").URL("category", "technology", "id", "42") - Farhad Kocharli

1 Answers

1
votes

Use cases if someone needs.

• Constructing redirects to send to a client - eg programmatically, so you don’t have to fix the URLs in your code elsewhere

• Building examples & tests

• Generating docs