Files
geo/server/internal/shared/auth/context.go
T

29 lines
511 B
Go
Raw Normal View History

package auth
import "context"
type Actor struct {
UserID int64
TenantID int64
Role string
}
type actorKey struct{}
func WithActor(ctx context.Context, actor Actor) context.Context {
return context.WithValue(ctx, actorKey{}, actor)
}
func ActorFromCtx(ctx context.Context) (Actor, bool) {
actor, ok := ctx.Value(actorKey{}).(Actor)
return actor, ok
}
func MustActor(ctx context.Context) Actor {
actor, ok := ActorFromCtx(ctx)
if !ok {
panic("auth: actor not in context")
}
return actor
}