aboutsummaryrefslogtreecommitdiff
path: root/common/context.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-01-22 16:04:19 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-01-22 16:04:19 +0100
commitf4368074a7cc07ad305ae9fb9b08d6b8dd3025eb (patch)
tree4fb677a7e41748d5db2ae57192f03d9443b909e5 /common/context.go
parent94a11e552b50a389a4e3a6b5fe7bdea4ce7097a4 (diff)
feat(context): create custom with config data in
Diffstat (limited to 'common/context.go')
-rw-r--r--common/context.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/common/context.go b/common/context.go
new file mode 100644
index 0000000..3a79264
--- /dev/null
+++ b/common/context.go
@@ -0,0 +1,51 @@
+package common
+
+import (
+ "context"
+
+ "gorm.io/gorm"
+)
+
+type key uint8
+
+const (
+ keyDB key = 0
+ keyDebug key = 1
+ keyAuthor key = 2
+)
+
+func SetDB(ctx context.Context, db *gorm.DB) context.Context {
+ return context.WithValue(ctx, keyDB, db)
+}
+
+func GetDB(ctx context.Context) *gorm.DB {
+ raw := ctx.Value(keyDB)
+ if raw == nil {
+ return nil
+ }
+ return raw.(*gorm.DB)
+}
+
+func SetDebug(ctx context.Context, b bool) context.Context {
+ return context.WithValue(ctx, keyDebug, b)
+}
+
+func IsDebug(ctx context.Context) bool {
+ raw := ctx.Value(keyDebug)
+ if raw == nil {
+ return false
+ }
+ return raw.(bool)
+}
+
+func SetAuthor(ctx context.Context, s string) context.Context {
+ return context.WithValue(ctx, keyAuthor, s)
+}
+
+func GetAuthor(ctx context.Context) string {
+ raw := ctx.Value(keyAuthor)
+ if raw == nil {
+ return ""
+ }
+ return raw.(string)
+}