From 32dac71694ed2ad6ecbde6cb191b1ea691463133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=91=D1=8B=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B2?= Date: Thu, 12 Nov 2026 10:36:15 +0500 Subject: [PATCH] docs: explain WithContext signature requirements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Виктор Быстров --- docs/configuration.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 0aaaf99dd..e9c8fdd05 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -68,8 +68,13 @@ user defined function calls a remote service, we may want to pass a context to t This is possible via the [`WithContext`](https://pkg.go.dev/github.com/expr-lang/expr#WithContext) option. -This option will modify function calls to include the context as the first argument (only if the function signature -accepts a context). +This option modifies function calls at compile time to include the context as the first argument (only if the function +signature accepts a context). For functions or methods supplied by the environment, pass the environment to +[`expr.Env`](https://pkg.go.dev/github.com/expr-lang/expr#Env) when compiling so their signatures are known. Supplying a +function only to `expr.Run` is too late: without its signature, the context argument is not inserted. + +Functions registered with [`expr.Function`](https://pkg.go.dev/github.com/expr-lang/expr#Function) can instead provide +their signature through the optional typed function argument; they do not also need to be supplied through `expr.Env`. ```expr customFunc(42) @@ -78,6 +83,7 @@ customFunc(ctx, 42) ``` Function `expr.WithContext()` takes the name of context variable. The context variable must be defined in the environment. +Its value is read from the environment passed to `expr.Run`, so a different context can be used for each execution. ```go env := map[string]any{