Handle an array of identifiers in a request using gorilla / mux

I need to process such a request using gorilla / mux:

/objects?id=JDYsh939&id=OYBpo726

As I understand it when reading the documentation, I can specify the following pattern: {name:pattern} , but I don’t know if this will work to indicate that the URL will contain the id parameter several times.

Any ideas?

+4
source share
1 answer

You do not need to specify a parameter for it, since query string parameters are included in the corresponding HttpRequest collection.

The following code shows how to handle them:

 r.HandleFunc("/objects", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello! Parameters: %v", r.URL.Query()) }) 

See https://golang.org/pkg/net/url/#pkg-examples for how to handle URL query string parameters.

+2
source

All Articles