Hi,
I am trying to update query parameters within a "http.Request". I expected to be able to do the following, however, the values are never updated.
ret := httpRequest.URL.Query().Get(name)
if len(ret) == 0 {
httpRequest.URL.Query().Add(name, value)
} else {
httpRequest.URL.Query().Set(name, value)
}
The only way I could get it to work is in the QuerySet function, but it feels a bit overkill?
func QuerySet(httpRequest *http.Request, name string, value string) (err error) {
ret := httpRequest.URL.Query().Get(name)
if len(ret) == 0 {
params := url.Values{}
for k, v := range httpRequest.URL.Query() {
params.Add(k, v[0] )
}
params.Add(name, value)
httpRequest.URL.RawQuery = params.Encode()
} else {
params := url.Values{}
for k, v := range httpRequest.URL.Query() {
params.Add(k, v[0] )
}
params.Set(name, value)
httpRequest.URL.RawQuery = params.Encode()
}
return nil
}
Thanks
Mark