So I'm doing this code.
I create a time, and pass it as an URL parameter. In my handler, I do this.
path := //some url + time.Now().String()
// put into url and execute a request.
updatedAtVar := r.URL.Query()["updated_at"][0]
fmt.Println(updatedAtVar)
What is coming out of time.Now().String()
is something like
2014-11-17 23:02:03 +0000 UTC
.
What is coming out of r.URL.Query()["updated_at"][0]
is
2014-11-17 23:02:03 0000 UTC
.
Why does this happen?
Maybe the question should be: Why does the (not shown) query string evaluate the value "2014-11-17 23:02:03 0000 UTC" when accessed?
Since "+" in a query string will be treated as a space when parsed (this is a historic rule) ..
HTML 5 specifies the following transformation for submitting HTML forms with the "get" method to a web server .. SPACE is encoded as '+' or '%20'
.. my hypothesis is the result of accessing the value in URL is really the following:
2014-11-17 23:02:03 0000 UTC
^^-- space space
A 'correct' URL would be foo?time=2014-11-17+23:02:03+%2B0000+UTC
, encoding +
as %2B
so it is not parsed as a space. An equivalent URL would be generated if using programmatic methods to generate URLs instead of building one by hand / string concatenation.