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:
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.
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.