I was using r.URL.Query("model") to retrieve a url param. Lets say "https://example.com?model=345;1" My expected behaviour is to retrieve: 345;1 But I only receive: 345 Is there a specific meaning behind it? and how i can force to get the full value. I am quite new go.
Asked
Active
Viewed 526 times
-1
-
3Does this answer your question? [Characters allowed in GET parameter](https://stackoverflow.com/questions/1455578/characters-allowed-in-get-parameter) – LeGEC Mar 10 '21 at 15:08
-
2[Do not post images of text](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). Please read [ask] to get the most out of StackOverflow. – JimB Mar 10 '21 at 15:23
1 Answers
0
As LeGEC indicated the problem is due the fact that the semi-colon (;) is a character that has (or could have) special meaning in URLs.
You can use "%#v" in your Go Printf example to see how Go parsed the query string:
package main
import "fmt"
import "net/url"
import "log"
func main() {
u, err := url.Parse("https://example.com?model=345;1")
if err != nil {
log.Fatal(err)
}
q := u.Query()
fmt.Printf("%#v",q)
}
Gives
url.Values{"1":[]string{""}, "model":[]string{"345"}}
You could use u.RawQuery
to get the entire string "model=345;1" and then parse it yourself. Not ideal, but perhaps a quick workaround.

Hector Correa
- 26,290
- 8
- 57
- 73