20 lines
600 B
Go
20 lines
600 B
Go
package domain
|
|
|
|
import "context"
|
|
|
|
type NotificationScope struct {
|
|
UserID int64
|
|
ReceiverType ReceiverType
|
|
}
|
|
type notificationScopeKey struct{}
|
|
|
|
func WithNotificationScope(ctx context.Context, userID int64, receiver ReceiverType) context.Context {
|
|
return context.WithValue(ctx, notificationScopeKey{}, NotificationScope{UserID: userID, ReceiverType: receiver})
|
|
}
|
|
func NotificationScopeFromContext(ctx context.Context) NotificationScope {
|
|
if scope, ok := ctx.Value(notificationScopeKey{}).(NotificationScope); ok {
|
|
return scope
|
|
}
|
|
return NotificationScope{ReceiverType: ReceiverTypeUser}
|
|
}
|