mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 21:00:06 +01:00
33 lines
620 B
Go
33 lines
620 B
Go
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
|
|
}
|