20 lines
387 B
Go
20 lines
387 B
Go
package system
|
|
|
|
import "context"
|
|
|
|
type actorContextKey struct{}
|
|
|
|
type Actor struct {
|
|
UserID uint
|
|
AuthorityID uint
|
|
}
|
|
|
|
func NewActorContext(ctx context.Context, actor Actor) context.Context {
|
|
return context.WithValue(ctx, actorContextKey{}, actor)
|
|
}
|
|
|
|
func ActorFromContext(ctx context.Context) (Actor, bool) {
|
|
actor, ok := ctx.Value(actorContextKey{}).(Actor)
|
|
return actor, ok
|
|
}
|