- Install the github.com/gorilla/sessions package using the go get command, as follows:
$ go get github.com/gorilla/sessions
- Create http-session.go where we will create a Gorilla cookie store to save and retrieve session information defining three handlers—/login, /home, and /logout—where we will be creating a valid session cookie, writing a response to an HTTP response stream, and invalidating a session cookie respectively, as follows:
package mainimport ( "fmt" "log" "net/http" "github.com/gorilla/sessions")const ( CONN_HOST = "localhost" CONN_PORT = "8080")var store *sessions.CookieStorefunc init() { store = sessions.NewCookieStore([]byte("secret-key"))}func home(w http.ResponseWriter, r *http.Request) { session, _ := ...