Files
moteva/server/internal/modules/sharing/context.go
T

31 lines
706 B
Go

package sharing
import "context"
type actorContextKey struct{}
type accessContextKey struct{}
func ContextWithActor(ctx context.Context, actor Actor) context.Context {
return context.WithValue(ctx, actorContextKey{}, actor)
}
func ActorFromContext(ctx context.Context) Actor {
if ctx == nil {
return Actor{}
}
actor, _ := ctx.Value(actorContextKey{}).(Actor)
return actor
}
func ContextWithAccess(ctx context.Context, access Access) context.Context {
return context.WithValue(ctx, accessContextKey{}, access)
}
func AccessFromContext(ctx context.Context) (Access, bool) {
if ctx == nil {
return Access{}, false
}
access, ok := ctx.Value(accessContextKey{}).(Access)
return access, ok
}