Creating your first HTTP cookie
Cookies play an important role when storing information on the client side and we can use their values to identify a user. Basically, cookies were invented to solve the problem of remembering information about the user or persistent-login authentication, which refers to websites being able to remember the identity of a principal between sessions.
Cookies are simple text files that web browsers create when you visit websites on the internet. Your device stores the text files locally, allowing your browser to access the cookie and pass data back to the original website, and are saved in name-value pairs.
How to do it…
- Install the
github.com/gorilla/securecookie
package using thego get
command, as follows:
$ go get github.com/gorilla/securecookie
- Create
http-cookie.go
, where we will create a Gorilla secure cookie to store and retrieve cookies, as follows:
package main import ( "fmt" "log" "net/http" "github.com/gorilla/securecookie" ) const ( CONN_HOST...