There's no Go library that I'm aware of that provides this
functionality. But it's not too complicated to implement yourself,
provided you know what you want to do.
To set a cookie, you send a Set-Cookie header in your HTTP response.
You'll then be able to read the Cookie header from the user's HTTP
request.
You will need to use the Response.AddHeader method:
http://golang.org/pkg/http/#Response.AddHeader
And access the Request.Header map:
http://golang.org/pkg/http/#Request
Andrew
For additional clarity, the ID is generated by concatenating the
remote address, current time (tv.tv_sec and tv.tv_usec) and a
pseudorandom number. It then passes this to a hash function (MD5 or
SHA1 or something else). Then it opens an entropy device (e.g.
/dev/urandom) and puts some of that data into the hash function. Then
it finalizes the hash. By default, it stores the data on disk in a
file referenced by the session ID; this can be changed.
> There's no Go library that I'm aware of that provides this
> functionality. But it's not too complicated to implement yourself,
> provided you know what you want to do.
Hopefully the above gives a little more insight as to how it might be
implemented. To my knowledge, there is no logic built in to attempt to
detect hijacking. Sessions are not horribly secure, and generally
shouldn't be used as a token of authentication.
--dho
SESSION usually rely on cookies, like Andrew said a single ID is sent
in a cookie or HTTP Request that identifies the data on the server.
HTTP is stateless, so I order to have some state an ID must be sent in
every request by the client so the server can associate that request
with the previous one.
Session ID by itself is not secure, can be hijacked (read XSRF).
Secure cookies can help but I don't know very much about then.
Using cookies with the Refer header and some other generated Header is
the best way to avoid XSRF. I use a meta tag with an special ID, so
every AJAX request send that ID, if the ID received by the server is
no related with that session ID the request is droped.
In GWT docs the explain a little about how that trick works (I don't
have the link right now).
--
André Moraes
http://andredevchannel.blogspot.com/
In that case a sessionid in the QueryString or a Hidden field in the
form will do the trick.
Beside that I don't know any other way to create persistent sessions
Including the remote IP breaks for some users with load-balancing
proxies. In such a setup, the HTTP requests can legitimately come from
a different IP address each time.
--Benny.