Implementing login and logout in web application
Whenever we want an application to be accessed by registered users, we have to implement a mechanism that asks for the user's credentials before allowing them to view any web pages, which we will be covering in this recipe.
Getting ready…
As we have already created an HTML form in one of our previous recipes, we will just update it to implement login and logout mechanisms using the gorilla/securecookie
package.
Note
See the Implementing login and logout in web application recipe in Chapter 2, Working with Templates, Static Files, and HTML Forms.
How to do it…
- Install
github.com/gorilla/mux
andgithub.com/gorilla/securecookie
using thego get
command, as follows:
$ go get github.com/gorilla/mux $ go get github.com/gorilla/securecookie
- Create
home.html
inside thetemplates
directory, as follows:
$ mkdir templates && cd templates && touch home.html
- Copy the following content to
home.html
:
<html> <head> <title><...