Friday, June 3, 2016

Authentication Wrapper Handler Using Go

In this post I will show how to secure your routes by wrapping http handler.
First add main.go file with following content.
Add a folder called templates and add home.html file with following contents.
Then build and run the application.
Output should be displayed like below.
Now we need to restrict access for /home route if "auth" cookie is not present. Add auth.go file which will contains all the authentication related functionalities.
Now we need to change the main function accordingly.
Build and run the application. You will see 404 page like below.

No comments:

Post a Comment