-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathrequest.go
More file actions
67 lines (54 loc) · 1.88 KB
/
request.go
File metadata and controls
67 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package context
import "context"
// readonlyCtxKey is a context key for read-only mode
type readonlyCtxKey struct{}
// WithReadonly adds read-only mode state to the context
func WithReadonly(ctx context.Context, enabled bool) context.Context {
return context.WithValue(ctx, readonlyCtxKey{}, enabled)
}
// IsReadonly retrieves the read-only mode state from the context
func IsReadonly(ctx context.Context) bool {
if enabled, ok := ctx.Value(readonlyCtxKey{}).(bool); ok {
return enabled
}
return false
}
// toolsetsCtxKey is a context key for the active toolsets
type toolsetsCtxKey struct{}
// WithToolsets adds the active toolsets to the context
func WithToolsets(ctx context.Context, toolsets []string) context.Context {
return context.WithValue(ctx, toolsetsCtxKey{}, toolsets)
}
// GetToolsets retrieves the active toolsets from the context
func GetToolsets(ctx context.Context) []string {
if toolsets, ok := ctx.Value(toolsetsCtxKey{}).([]string); ok {
return toolsets
}
return nil
}
// toolsCtxKey is a context key for tools
type toolsCtxKey struct{}
// WithTools adds the tools to the context
func WithTools(ctx context.Context, tools []string) context.Context {
return context.WithValue(ctx, toolsCtxKey{}, tools)
}
// GetTools retrieves the tools from the context
func GetTools(ctx context.Context) []string {
if tools, ok := ctx.Value(toolsCtxKey{}).([]string); ok {
return tools
}
return nil
}
// lockdownCtxKey is a context key for lockdown mode
type lockdownCtxKey struct{}
// WithLockdownMode adds lockdown mode state to the context
func WithLockdownMode(ctx context.Context, enabled bool) context.Context {
return context.WithValue(ctx, lockdownCtxKey{}, enabled)
}
// IsLockdownMode retrieves the lockdown mode state from the context
func IsLockdownMode(ctx context.Context) bool {
if enabled, ok := ctx.Value(lockdownCtxKey{}).(bool); ok {
return enabled
}
return false
}