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/sessions/functions.go | |
| parent | 65a143a0871c35989b7c7ea6723d39a0585c089e (diff) | |
| download | echoes-of-vaelun-main.tar.xz echoes-of-vaelun-main.zip | |
Diffstat (limited to 'nexus/sessions/functions.go')
| -rw-r--r-- | nexus/sessions/functions.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/nexus/sessions/functions.go b/nexus/sessions/functions.go new file mode 100644 index 0000000..4baedb1 --- /dev/null +++ b/nexus/sessions/functions.go @@ -0,0 +1,55 @@ +package sessions
+
+import (
+ "nexus/utils/collections"
+
+ "github.com/gofiber/fiber/v2/middleware/session"
+ "github.com/google/uuid"
+)
+
+func CreateSession(sess *session.Session, accountID uuid.UUID) error {
+ return Set(sess, SessionAccountIDKey, accountID.String())
+}
+
+func DestroySession(sess *session.Session) error {
+ return Delete(sess, SessionAccountIDKey)
+}
+
+func GetSessionAccountID(sess *session.Session) (uuid.UUID, bool) {
+ value := Get(sess, SessionAccountIDKey)
+ if value == nil {
+ return uuid.Nil, false
+ }
+
+ str, ok := value.(string)
+ if !ok {
+ return uuid.Nil, false
+ }
+
+ id, err := uuid.Parse(str)
+ if err != nil {
+ return uuid.Nil, false
+ }
+
+ return id, true
+}
+
+func SetFlash(sess *session.Session, data collections.Record[string, any]) error {
+ return Set(sess, SessionFlashKey, data)
+}
+
+func GetFlash(sess *session.Session) collections.Record[string, any] {
+ value := Get(sess, SessionFlashKey)
+ if value == nil {
+ return nil
+ }
+ m, ok := value.(collections.Record[string, any])
+ if !ok {
+ return nil
+ }
+ return m
+}
+
+func ClearFlash(sess *session.Session) error {
+ return Delete(sess, SessionFlashKey)
+}
|
