A full-stack application using Golang's Fiber framework with session-based authentication using Fiber's built-in middleware. Requests to the backend are controlled by </> htmx (hypermedia only).
A real-world example of how to use Fiber sessions with Storage package.
Run localhost:3000 from multiple browsers to see active sessions for different users.
The Session middleware uses the Storage package to support various databases through a single interface. The default configuration for this middleware saves data to memory.
In this example uses SQLite3 Storage package to persist users sessions.
Storage package can create sessions table for you at init time but for the purpose of this example I created it manually expanding its structure with an "u" column to better query all user-related sessions.
On the other hand, the styling of the views is achieved through Tailwind CSS and DaisyUI that are obtained from their respective CDNs.
Finally, minimal use of _hyperscript is made to achieve the action of closing the alerts when they are displayed.
Besides the obvious prerequisite of having Go! on your machine, you must have Air installed for hot reloading when editing code.
Start the app in development mode:
$ air # Ctrl + C to stop the application
Build for production:
$ go build -ldflags="-s -w" -o ./bin/main . # ./bin/main to run the application