aboutsummaryrefslogtreecommitdiff
path: root/contextlib
diff options
context:
space:
mode:
Diffstat (limited to 'contextlib')
-rw-r--r--contextlib/context.go8
-rw-r--r--contextlib/user.go21
2 files changed, 29 insertions, 0 deletions
diff --git a/contextlib/context.go b/contextlib/context.go
new file mode 100644
index 0000000..34c511e
--- /dev/null
+++ b/contextlib/context.go
@@ -0,0 +1,8 @@
+package contextlib
+
+type contextKey string
+
+var (
+ ThemeKey contextKey = "theme"
+ UserKey contextKey = "user"
+)
diff --git a/contextlib/user.go b/contextlib/user.go
new file mode 100644
index 0000000..6ef12d6
--- /dev/null
+++ b/contextlib/user.go
@@ -0,0 +1,21 @@
+package contextlib
+
+import (
+ "context"
+
+ "gitrepo.ru/neonxp/gorum/models"
+)
+
+func GetUser(ctx context.Context) *models.User {
+ u := ctx.Value(UserKey)
+ if u == nil {
+ return nil
+ }
+
+ user, ok := u.(models.User)
+ if !ok {
+ return nil
+ }
+
+ return &user
+}