Files
releases/v1/ast/rego_compiler.go
Stephan Renatus 52381423d3 test+eval: add helper to smuggle compiler through context
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-23 22:12:13 +02:00

18 lines
358 B
Go

package ast
import "context"
type regoCompileCtx struct{}
func WithCompiler(ctx context.Context, c *Compiler) context.Context {
return context.WithValue(ctx, regoCompileCtx{}, c)
}
func CompilerFromContext(ctx context.Context) (*Compiler, bool) {
if ctx == nil {
return nil, false
}
v, ok := ctx.Value(regoCompileCtx{}).(*Compiler)
return v, ok
}