How do I represent a path without query string?
Eg.:
-
www.example.com/user
instead of -
www.example.com/user?id=1
The following code didn't work:
Go:
if r.URL.Path[4:] != "" {
//do something
}
How do I represent a path without query string?
Eg.:
www.example.com/user
instead of www.example.com/user?id=1
The following code didn't work:
Go:
if r.URL.Path[4:] != "" {
//do something
}
To add parameters to an url, you would use Values()
.
That means, an URL without any parameters would have its 'Values' length set to 0:
if len(r.URL.Query()) == 0 {
}
That should be the same as the r.URL.RawQuery
suggested by Dewy Broto in the comments:
if r.URL.RawQuery == "" {
}
Or you can check for the presence if the key 'id
' in the Values()
map.
if r.URL.Query().Get("id") == "" {
//do something here
}