1package access
2
3import "context"
4
5// ContextKey is the context key for the access level.
6var ContextKey = &struct{ string }{"access"}
7
8// FromContext returns the access level from the context.
9func FromContext(ctx context.Context) AccessLevel {
10 if ac, ok := ctx.Value(ContextKey).(AccessLevel); ok {
11 return ac
12 }
13
14 return -1
15}
16
17// WithContext returns a new context with the access level.
18func WithContext(ctx context.Context, ac AccessLevel) context.Context {
19 return context.WithValue(ctx, ContextKey, ac)
20}