diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-11-02 00:00:35 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-11-02 00:00:35 +0900 |
| commit | 104341ddc4add57f83c58cb3fabb23b6fbfdd3e4 (patch) | |
| tree | 862b109fe257e6170a88929729dae3bddfb6eb49 /backend/context/user.go | |
| parent | ba1e0c904f810193f25d4f88cc2bb168f1d625fe (diff) | |
| download | feedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.tar.gz feedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.tar.zst feedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.zip | |
Diffstat (limited to 'backend/context/user.go')
| -rw-r--r-- | backend/context/user.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/backend/context/user.go b/backend/context/user.go new file mode 100644 index 0000000..b8987e4 --- /dev/null +++ b/backend/context/user.go @@ -0,0 +1,20 @@ +package context + +import ( + "context" +) + +type contextKey string + +const userIDContextKey contextKey = "user_id" + +// SetUserID adds the user ID to the context +func SetUserID(ctx context.Context, userID int64) context.Context { + return context.WithValue(ctx, userIDContextKey, userID) +} + +// GetUserID retrieves the user ID from the request context +func GetUserID(ctx context.Context) (int64, bool) { + userID, ok := ctx.Value(userIDContextKey).(int64) + return userID, ok +} |
