Git Product home page Git Product logo

gofiber-htmx-sessions's Introduction

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 ๐Ÿ˜€!!

gofiber-htmx-sessions's People

Contributors

emarifer avatar

Watchers

 avatar

Forkers

krishmanohar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.