In an http request, I want to know if a request contains a specific parameter, similar to PHP's isset
function. How to test it in Go? Thanks.
Once you have parsed the request, you can always check the parameter's value type to be equal to that type's zero value.
For example, you can use the "comma, ok" idiom to check query parameters:
u, err := url.Parse("http://google.com/search?q=term")
if err != nil {
log.Fatal(err)
}
q := u.Query()
if _, ok := q["q"]; ok {
// process q
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With