diff options
| author | Bobby <[email protected]> | 2026-03-29 22:52:46 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-29 22:52:46 +0530 |
| commit | 9eb9b7f4bd552a641235764f66483e1f940fcfd9 (patch) | |
| tree | da520b923b5e6758d5457b6233dd6671fc640914 /nexus/utils/shortcuts/flash.go | |
| parent | 65a143a0871c35989b7c7ea6723d39a0585c089e (diff) | |
| download | echoes-of-vaelun-main.tar.xz echoes-of-vaelun-main.zip | |
Diffstat (limited to 'nexus/utils/shortcuts/flash.go')
| -rw-r--r-- | nexus/utils/shortcuts/flash.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nexus/utils/shortcuts/flash.go b/nexus/utils/shortcuts/flash.go new file mode 100644 index 0000000..c82b37d --- /dev/null +++ b/nexus/utils/shortcuts/flash.go @@ -0,0 +1,36 @@ +package shortcuts
+
+import (
+ "nexus/sessions"
+ "nexus/utils/collections"
+
+ "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v2/middleware/session"
+)
+
+func Flash(context *fiber.Ctx, data collections.Record[string, any]) error {
+ sess, ok := context.Locals(sessions.SessionLocalKey).(*session.Session)
+ if !ok {
+ return nil
+ }
+ return sessions.SetFlash(sess, data)
+}
+
+func ConsumeFlash(context *fiber.Ctx) collections.Record[string, any] {
+ sess, ok := context.Locals(sessions.SessionLocalKey).(*session.Session)
+ if !ok {
+ return nil
+ }
+ data := sessions.GetFlash(sess)
+ if data != nil {
+ _ = sessions.ClearFlash(sess)
+ }
+ return data
+}
+
+func RedirectWithFlash(context *fiber.Ctx, routeName string, data collections.Record[string, any]) error {
+ if err := Flash(context, data); err != nil {
+ return err
+ }
+ return Redirect(context, routeName)
+}
|
