Member-only story
How To Create A Simple Web Login Using Gin For Golang
In this example, I will show you how to build a simple login system for a web app using the Gin HTTP Web Framework for Golang.
Here I present an example of a simple proof of concept web app with a login system and session management. It is written in the Go language (Golang), and it makes use of the Gin HTTP Web Framework. The example, as provided here, can easily be extended.
The way I structured the code was inspired by how Akhil Sharma structured the code for his “Restaurant Management Backend” example. Also, some of the authentication, login, and logout code has been adapted from Depado’s Authentication Example. The rest is based on my previous articles. See references at the end of the article for links to these.
Prerequisites
When debugging, make sure that the HTTP cache is disabled. This also requires that the Inspector or DevTools are opened while debugging.
- If you use the Firefox Inspector, go to the settings, locate the advanced settings, and check ‘Disable HTTP Cache (when toolbox is open).’
- For the Chrome DevTools, go to the Preferences, locate the Network Settings, and check ‘Disable Cache (while DevTools is open).’
Directory Structure

In the above screenshot, you can see the file and directory layout of the project. The directories you see here are, in turn, subdirectories of a directory called /gin_session_auth
. This is important to note as this is also the project's name.
When addressing the packages, we always start with the name of the project and then add the package's name. For example, if you want to address the controllers
package, you’d write "gin_session_auth/controllers"
. You’ll see this in the imports in the files listed below.