1package proto23import "context"45// ContextKeyRepository is the context key for the repository.6var ContextKeyRepository = &struct{ string }{"repository"}78// ContextKeyUser is the context key for the user.9var ContextKeyUser = &struct{ string }{"user"}1011// RepositoryFromContext returns the repository from the context.12func RepositoryFromContext(ctx context.Context) Repository {13 if r, ok := ctx.Value(ContextKeyRepository).(Repository); ok {14 return r15 }16 return nil17}1819// UserFromContext returns the user from the context.20func UserFromContext(ctx context.Context) User {21 if u, ok := ctx.Value(ContextKeyUser).(User); ok {22 return u23 }24 return nil25}2627// WithRepositoryContext returns a new context with the repository.28func WithRepositoryContext(ctx context.Context, r Repository) context.Context {29 return context.WithValue(ctx, ContextKeyRepository, r)30}3132// WithUserContext returns a new context with the user.33func WithUserContext(ctx context.Context, u User) context.Context {34 return context.WithValue(ctx, ContextKeyUser, u)35}