How to parse string into url.Values in golang?
You could use url.ParseQuery
to convert the raw query to url.Values
with unescaping
package main
import (
"fmt"
"net/url"
)
func main() {
t := "honeypot=&name=Zelalem+Mekonen&email=zola%40programmer.net&message=Hello+And+this+is+a+test+message..."
v, err := url.ParseQuery(t)
if err != nil {
panic(err)
}
fmt.Println(v)
}
Result:
map[honeypot:[] name:[Zelalem Mekonen] email:[[email protected]] message:[Hello And this is a test message...]]
You could first decode the URL with net/url/QueryUnescape
.
It does converts '+
' into '' (space).
Then you can start splitting the decoded string, or use net/url/#ParseRequestURI
and get the URL.Query
.