InjectContext injects an existing Context as the first middleware and then wraps a function with middleware using that context. It returns a cli.ActionFunc with the cli.Context added to the Context. By injecting the existing context as the first middleware, we ensure that it's the Context all later
(injectedCtx context.Context, fn func(context.Context) error, middleware ...func(context.Context) (context.Context, error))
| 12 | // By injecting the existing context as the first middleware, we ensure |
| 13 | // that it's the Context all later middlewares operate on. |
| 14 | func InjectContext(injectedCtx context.Context, fn func(context.Context) error, middleware ...func(context.Context) (context.Context, error)) cli.ActionFunc { |
| 15 | injectedMiddleware := []func(context.Context) (context.Context, error){ |
| 16 | func(context.Context) (context.Context, error) { |
| 17 | return injectedCtx, nil |
| 18 | }, |
| 19 | } |
| 20 | injectedMiddleware = append(injectedMiddleware, middleware...) |
| 21 | //nolint:contextcheck // context is injected in fn |
| 22 | return wrap(fn, injectedMiddleware...) |
| 23 | } |
| 24 | |
| 25 | type cliCtxKey struct{} |
| 26 |
searching dependent graphs…