-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathrequest.go
More file actions
35 lines (28 loc) · 987 Bytes
/
request.go
File metadata and controls
35 lines (28 loc) · 987 Bytes
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
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
}
// toolsetCtxKey is a context key for the active toolset
type toolsetCtxKey struct{}
// WithToolset adds the active toolset to the context
func WithToolset(ctx context.Context, toolset string) context.Context {
return context.WithValue(ctx, toolsetCtxKey{}, toolset)
}
// GetToolset retrieves the active toolset from the context
func GetToolset(ctx context.Context) string {
if toolset, ok := ctx.Value(toolsetCtxKey{}).(string); ok {
return toolset
}
return ""
}