I think this can be seen by accesing the map directly
_, ok := u.Query()["query2"] // will be true
_, ok := u.Query()["query3"] // isn't
Fabrice
On 14/07/2019 06:55, i...@ecnepsnai.com wrote:
The URI RFC is pretty sparse when it comes to query parameters, but
doesn't mandate that queries must have values, meaning that this is a
valid URI:
"https://example.com/?query1=value1&query2"
But the net/url package does not provide an easy way to see that
"query2" is present in the URL through the Values object because it
returns an empty string, just like for non-present queries.
Example: https://play.golang.org/p/fo5_tcNs6PZ
package main
import (
"net/url"
"fmt"
)
func main() {
// According to the RFC spec, a query parameter with no value is
still valid
// But the "net/url" package doesn't make it possible to
distinguish between a query with no value, and a query that isn't present
// since both return an empty string
u, _ := url.Parse("https://example.com/?query1=value1&query2")
fmt.Printf("%#v\n", u.Query().Encode())
fmt.Printf("%#v\n", u.Query().Get("query1")) // should print "value1"
fmt.Printf("%#v\n", u.Query().Get("query2")) // should print..
something??
fmt.Printf("%#v\n", u.Query().Get("query3")) // query3 doesn't exist
}
Maybe there needs to be something like u.Query().Present("query2")
that returns a bool if the query is present, even if it doesn't have a
value?
Sorry if this has been discussed before, I searched for topics about
this and couldn't find any.
--
You received this message because you are subscribed to the Google
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to golang-nuts+unsubscr...@googlegroups.com
<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/c309be14-54ad-4cdd-be58-272b2a531fbb%40googlegroups.com
<https://groups.google.com/d/msgid/golang-nuts/c309be14-54ad-4cdd-be58-272b2a531fbb%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/59a41ffb-a764-2ef6-06cd-eaaa7291b623%40gmail.com.
For more options, visit https://groups.google.com/d/optout.