1package proto
 2
 3import "context"
 4
 5// ContextKeyRepository is the context key for the repository.
 6var ContextKeyRepository = &struct{ string }{"repository"}
 7
 8// ContextKeyUser is the context key for the user.
 9var ContextKeyUser = &struct{ string }{"user"}
10
11// RepositoryFromContext returns the repository from the context.
12func RepositoryFromContext(ctx context.Context) Repository {
13	if r, ok := ctx.Value(ContextKeyRepository).(Repository); ok {
14		return r
15	}
16	return nil
17}
18
19// UserFromContext returns the user from the context.
20func UserFromContext(ctx context.Context) User {
21	if u, ok := ctx.Value(ContextKeyUser).(User); ok {
22		return u
23	}
24	return nil
25}
26
27// 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}
31
32// 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}