Reputation: 35
I have to check if URL param exists before to do some type of validation. How can i do this?
if param come empty like this: http://myurl.com?myparam= then myParam == "" is true, but if the url come this way http://myurl.com (with out params) then myParam == "" also is true... so i need some way to validate if param come in the url
# example
# http://myurl.com?myparam=johndoe
// validate if param exists, here i dont know how to do
#
#
// then do some validation
func validateMyParamIsNotNumber(r *http.Request, resultMessage *string) {
myParam := r.FormValue("myparam")
if myParam != "" && isNotNumber(product) {
*resultMessage = "The myparam filter must be a number"
return
}
}
Upvotes: 1
Views: 5438
Reputation: 121139
Check for presence of the key in Request.Form using map index with multiple assignment. Parse the form before checking the map.
func validateMyParamIsNotNumber(r *http.Request, resultMessage *string) {
r.ParseForm()
_, hasMyParam := r.Form["myparam"]
...
Upvotes: 5