Skip to content

Full-stack app using Go Fiber's SQLite3 storage package to persist user sessions & HTMX on the frontend

Notifications You must be signed in to change notification settings

KrishManohar/gofiber-htmx-sessions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Fiber HTMx Sessions App (Demo)

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).

Sessions & SQLite3

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.

Explanation

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.


Screenshots:

Profile Page with success alert:


Sign Up Page with error alert:


Setup:

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

Happy coding 😀!!

About

Full-stack app using Go Fiber's SQLite3 storage package to persist user sessions & HTMX on the frontend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 66.0%
  • HTML 34.0%