-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
34 lines (27 loc) · 883 Bytes
/
context.go
File metadata and controls
34 lines (27 loc) · 883 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
package forgeui
import "context"
// Context keys for ForgeUI
type contextKey string
const (
themeKey contextKey = "forgeui_theme"
configKey contextKey = "forgeui_config"
requestKey contextKey = "forgeui_request"
)
// WithTheme adds theme to context
func WithTheme(ctx context.Context, theme any) context.Context {
return context.WithValue(ctx, themeKey, theme)
}
// ThemeFromContext retrieves theme from context
func ThemeFromContext(ctx context.Context) (any, bool) {
theme := ctx.Value(themeKey)
return theme, theme != nil
}
// WithConfig adds config to context
func WithConfig(ctx context.Context, config *Config) context.Context {
return context.WithValue(ctx, configKey, config)
}
// ConfigFromContext retrieves config from context
func ConfigFromContext(ctx context.Context) (*Config, bool) {
config, ok := ctx.Value(configKey).(*Config)
return config, ok
}