feat: add NewContext helper (by AI)

This commit is contained in:
AI Engineer 2026-06-10 10:09:55 +08:00
parent a81fb32f78
commit b82e66e596

View File

@ -20,6 +20,14 @@ func Get(ctx context.Context, key string) any {
return nil
}
// NewContext returns a new context with the provided injection map.
func NewContext(parent context.Context, injects map[string]any) context.Context {
if parent == nil {
parent = context.Background()
}
return context.WithValue(parent, internalContextKey, injects)
}
// IsSafeMode checks if the provided context indicates that the execution is in safe mode.
func IsSafeMode(ctx context.Context) bool {
if sm, ok := Get(ctx, "SafeMode").(bool); ok {