Passing a query parameter to the Go HTTP request handler using the MUX package

Call FormValue to get a query parameter:

token := req.FormValue("token")

req is a the *http.Request

An alternative is to call ParseForm and access req.Form directly:

if err := req.ParseForm(); err != nil {
   // handle error
}
token := req.Form.Get("token")

The OP asks in a comment how to map "token" to "access_token" for an external package that's looking "access_token". Execute this code before calling the external package:

if err := req.ParseForm(); err != nil {
   // handle error
}
req.Form["access_token"] = req.Form["token"]

When the external package calls req.Form.Get("access_token"), it will get the same value as the "token" parameter.


Depending on the way you want to parse the token , if its coming from the form or the URL.

The first answer can be used if the token is being sent from the form while in case of a URL, I would suggest using this. This works for me

token := req.URL.Query().Get("token")