2024-09-18 12:10:08 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
2024-11-27 12:23:56 +01:00
|
|
|
type ctxUserIdKey struct{}
|
2024-09-18 12:10:08 +02:00
|
|
|
|
|
|
|
|
// ContextGetUserId return the UserId stored in the context, if it exists.
|
|
|
|
|
func ContextGetUserId(ctx context.Context) (string, bool) {
|
2024-11-27 12:23:56 +01:00
|
|
|
val, ok := ctx.Value(ctxUserIdKey{}).(string)
|
2024-09-18 12:10:08 +02:00
|
|
|
return val, ok
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func addUserIdToContext(ctx context.Context, userId string) context.Context {
|
2024-11-27 12:23:56 +01:00
|
|
|
return context.WithValue(ctx, ctxUserIdKey{}, userId)
|
2024-09-18 12:10:08 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-27 12:23:56 +01:00
|
|
|
type ctxProjectIdKey struct{}
|
|
|
|
|
|
2024-09-18 12:10:08 +02:00
|
|
|
// ContextGetProjectId return the ProjectID stored in the context, if it exists.
|
|
|
|
|
func ContextGetProjectId(ctx context.Context) (string, bool) {
|
2024-11-27 12:23:56 +01:00
|
|
|
val, ok := ctx.Value(ctxProjectIdKey{}).(string)
|
2024-09-18 12:10:08 +02:00
|
|
|
return val, ok
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func addProjectIdToContext(ctx context.Context, projectId string) context.Context {
|
2024-11-27 12:23:56 +01:00
|
|
|
return context.WithValue(ctx, ctxProjectIdKey{}, projectId)
|
2024-09-18 12:10:08 +02:00
|
|
|
}
|