mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 12:50:05 +01:00
initial rebuild
This commit is contained in:
32
internal/ctxutil/context.go
Normal file
32
internal/ctxutil/context.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package ctxutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type ctxKey string
|
||||
|
||||
const (
|
||||
keyUserID ctxKey = "user_id"
|
||||
keyOrgID ctxKey = "org_id"
|
||||
)
|
||||
|
||||
func WithUserID(ctx context.Context, id uuid.UUID) context.Context {
|
||||
return context.WithValue(ctx, keyUserID, id)
|
||||
}
|
||||
|
||||
func UserID(ctx context.Context) (uuid.UUID, bool) {
|
||||
v, ok := ctx.Value(keyUserID).(uuid.UUID)
|
||||
return v, ok
|
||||
}
|
||||
|
||||
func WithOrgID(ctx context.Context, orgID uuid.UUID) context.Context {
|
||||
return context.WithValue(ctx, keyOrgID, orgID)
|
||||
}
|
||||
|
||||
func OrgID(ctx context.Context) (uuid.UUID, bool) {
|
||||
v, ok := ctx.Value(keyOrgID).(uuid.UUID)
|
||||
return v, ok
|
||||
}
|
||||
Reference in New Issue
Block a user