Documentation

Overview

    Package rego exposes high level APIs for evaluating Rego policies.

    Index

    Examples

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func Compiler

    func Compiler(c *ast.Compiler) func(r *Rego)

      Compiler returns an argument that sets the Rego compiler.

      func DisableInlining

      func DisableInlining(paths []string) func(r *Rego)

        DisableInlining adds a set of paths to exclude from partial evaluation inlining.

        func Dump

        func Dump(w io.Writer) func(r *Rego)

          Dump returns an argument that sets the writer to dump debugging information to.

          func Function1

          func Function1(decl *Function, f Builtin1) func(*Rego)

            Function1 returns an option that adds a built-in function to the Rego object.

            func Function2

            func Function2(decl *Function, f Builtin2) func(*Rego)

              Function2 returns an option that adds a built-in function to the Rego object.

              func Function3

              func Function3(decl *Function, f Builtin3) func(*Rego)

                Function3 returns an option that adds a built-in function to the Rego object.

                func Function4

                func Function4(decl *Function, f Builtin4) func(*Rego)

                  Function4 returns an option that adds a built-in function to the Rego object.

                  func FunctionDecl

                  func FunctionDecl(decl *Function) func(*Rego)

                    FunctionDecl returns an option that adds a custom-built-in function __declaration__. NO implementation is provided. This is used for non-interpreter execution envs (e.g., Wasm).

                    func FunctionDyn

                    func FunctionDyn(decl *Function, f BuiltinDyn) func(*Rego)

                      FunctionDyn returns an option that adds a built-in function to the Rego object.

                      func Imports

                      func Imports(p []string) func(r *Rego)

                        Imports returns an argument that adds a Rego import to the query's context.

                        func Input

                        func Input(x interface{}) func(r *Rego)

                          Input returns an argument that sets the Rego input document. Input should be a native Go value representing the input document.

                          func Instrument

                          func Instrument(yes bool) func(r *Rego)

                            Instrument returns an argument that enables instrumentation for diagnosing performance issues.

                            func InterQueryBuiltinCache

                            func InterQueryBuiltinCache(c cache.InterQueryCache) func(r *Rego)

                              InterQueryBuiltinCache sets the inter-query cache that built-in functions can utilize during evaluation.

                              func IsPartialEvaluationNotEffectiveErr

                              func IsPartialEvaluationNotEffectiveErr(err error) bool

                                IsPartialEvaluationNotEffectiveErr returns true if err is an error returned by this package to indicate that partial evaluation was ineffective.

                                func Load

                                func Load(paths []string, filter loader.Filter) func(r *Rego)

                                  Load returns an argument that adds a filesystem path to load data and Rego modules from. Any file with a *.rego, *.yaml, or *.json extension will be loaded. The path can be either a directory or file, directories are loaded recursively. The optional ignore string patterns can be used to filter which files are used. The Load option can only be used once. Note: Loading files will require a write transaction on the store.

                                  func LoadBundle

                                  func LoadBundle(path string) func(r *Rego)

                                    LoadBundle returns an argument that adds a filesystem path to load a bundle from. The path can be a compressed bundle file or a directory to be loaded as a bundle. Note: Loading bundles will require a write transaction on the store.

                                    func Metrics

                                    func Metrics(m metrics.Metrics) func(r *Rego)

                                      Metrics returns an argument that sets the metrics collection.

                                      func Module

                                      func Module(filename, input string) func(r *Rego)

                                        Module returns an argument that adds a Rego module.

                                        func Package

                                        func Package(p string) func(r *Rego)

                                          Package returns an argument that sets the Rego package on the query's context.

                                          func ParsedBundle

                                          func ParsedBundle(name string, b *bundle.Bundle) func(r *Rego)

                                            ParsedBundle returns an argument that adds a bundle to be loaded.

                                            func ParsedImports

                                            func ParsedImports(imp []*ast.Import) func(r *Rego)

                                              ParsedImports returns an argument that adds Rego imports to the query's context.

                                              func ParsedInput

                                              func ParsedInput(x ast.Value) func(r *Rego)

                                                ParsedInput returns an argument that sets the Rego input document.

                                                func ParsedModule

                                                func ParsedModule(module *ast.Module) func(*Rego)

                                                  ParsedModule returns an argument that adds a parsed Rego module. If a string module with the same filename name is added, it will override the parsed module.

                                                  func ParsedPackage

                                                  func ParsedPackage(pkg *ast.Package) func(r *Rego)

                                                    ParsedPackage returns an argument that sets the Rego package on the query's context.

                                                    func ParsedQuery

                                                    func ParsedQuery(q ast.Body) func(r *Rego)

                                                      ParsedQuery returns an argument that sets the Rego query.

                                                      func ParsedUnknowns

                                                      func ParsedUnknowns(unknowns []*ast.Term) func(r *Rego)

                                                        ParsedUnknowns returns an argument that sets the values to treat as unknown during partial evaluation.

                                                        func PartialNamespace

                                                        func PartialNamespace(ns string) func(r *Rego)

                                                          PartialNamespace returns an argument that sets the namespace to use for partial evaluation results. The namespace must be a valid package path component.

                                                          func PrintTrace

                                                          func PrintTrace(w io.Writer, r *Rego)

                                                            PrintTrace is a helper function to write a human-readable version of the trace to the writer w.

                                                            func PrintTraceWithLocation

                                                            func PrintTraceWithLocation(w io.Writer, r *Rego)

                                                              PrintTraceWithLocation is a helper function to write a human-readable version of the trace to the writer w.

                                                              func Query

                                                              func Query(q string) func(r *Rego)

                                                                Query returns an argument that sets the Rego query.

                                                                func QueryTracer

                                                                func QueryTracer(t topdown.QueryTracer) func(r *Rego)

                                                                  QueryTracer returns an argument that adds a query tracer to r.

                                                                  func RegisterBuiltin1

                                                                  func RegisterBuiltin1(decl *Function, impl Builtin1)

                                                                    RegisterBuiltin1 adds a built-in function globally inside the OPA runtime.

                                                                    func RegisterBuiltin2

                                                                    func RegisterBuiltin2(decl *Function, impl Builtin2)

                                                                      RegisterBuiltin2 adds a built-in function globally inside the OPA runtime.

                                                                      func RegisterBuiltin3

                                                                      func RegisterBuiltin3(decl *Function, impl Builtin3)

                                                                        RegisterBuiltin3 adds a built-in function globally inside the OPA runtime.

                                                                        func RegisterBuiltin4

                                                                        func RegisterBuiltin4(decl *Function, impl Builtin4)

                                                                          RegisterBuiltin4 adds a built-in function globally inside the OPA runtime.

                                                                          func RegisterBuiltinDyn

                                                                          func RegisterBuiltinDyn(decl *Function, impl BuiltinDyn)

                                                                            RegisterBuiltinDyn adds a built-in function globally inside the OPA runtime.

                                                                            func Resolver

                                                                            func Resolver(ref ast.Ref, r resolver.Resolver) func(r *Rego)

                                                                              Resolver sets a Resolver for a specified ref path.

                                                                              func Runtime

                                                                              func Runtime(term *ast.Term) func(r *Rego)

                                                                                Runtime returns an argument that sets the runtime data to provide to the evaluation engine.

                                                                                func Schemas

                                                                                func Schemas(x *ast.SchemaSet) func(r *Rego)

                                                                                  Schemas sets the schemaSet

                                                                                  func ShallowInlining

                                                                                  func ShallowInlining(yes bool) func(r *Rego)

                                                                                    ShallowInlining prevents rules that depend on unknown values from being inlined. Rules that only depend on known values are inlined.

                                                                                    func SkipBundleVerification

                                                                                    func SkipBundleVerification(yes bool) func(r *Rego)

                                                                                      SkipBundleVerification skips verification of a signed bundle.

                                                                                      func SkipPartialNamespace

                                                                                      func SkipPartialNamespace(yes bool) func(r *Rego)

                                                                                        SkipPartialNamespace disables namespacing of partial evalution results for support rules generated from policy. Synthetic support rules are still namespaced.

                                                                                        func Store

                                                                                        func Store(s storage.Store) func(r *Rego)

                                                                                          Store returns an argument that sets the policy engine's data storage layer.

                                                                                          If using the Load, LoadBundle, or ParsedBundle options then a transaction must also be provided via the Transaction() option. After loading files or bundles the transaction should be aborted or committed.

                                                                                          func StrictBuiltinErrors

                                                                                          func StrictBuiltinErrors(yes bool) func(r *Rego)

                                                                                            StrictBuiltinErrors tells the evaluator to treat all built-in function errors as fatal errors.

                                                                                            func Target

                                                                                            func Target(t string) func(r *Rego)

                                                                                              Target sets the runtime to exercise.

                                                                                              func Time

                                                                                              func Time(x time.Time) func(r *Rego)

                                                                                                Time sets the wall clock time to use during policy evaluation. Prepared queries do not inherit this parameter. Use EvalTime to set the wall clock time when executing a prepared query.

                                                                                                func Trace

                                                                                                func Trace(yes bool) func(r *Rego)

                                                                                                  Trace returns an argument that enables tracing on r.

                                                                                                  func Tracer

                                                                                                  func Tracer(t topdown.Tracer) func(r *Rego)

                                                                                                    Tracer returns an argument that adds a query tracer to r. Deprecated: Use QueryTracer instead.

                                                                                                    func Transaction

                                                                                                    func Transaction(txn storage.Transaction) func(r *Rego)

                                                                                                      Transaction returns an argument that sets the transaction to use for storage layer operations.

                                                                                                      Requires the store associated with the transaction to be provided via the Store() option. If using Load(), LoadBundle(), or ParsedBundle() options the transaction will likely require write params.

                                                                                                      func Unknowns

                                                                                                      func Unknowns(unknowns []string) func(r *Rego)

                                                                                                        Unknowns returns an argument that sets the values to treat as unknown during partial evaluation.

                                                                                                        func UnsafeBuiltins

                                                                                                        func UnsafeBuiltins(unsafeBuiltins map[string]struct{}) func(r *Rego)

                                                                                                          UnsafeBuiltins sets the built-in functions to treat as unsafe and not allow. This option is ignored for module compilation if the caller supplies the compiler. This option is always honored for query compilation. Provide an empty (non-nil) map to disable checks on queries.

                                                                                                          Types

                                                                                                          type Builtin1

                                                                                                          type Builtin1 func(bctx BuiltinContext, op1 *ast.Term) (*ast.Term, error)

                                                                                                            Builtin1 defines a built-in function that accepts 1 argument.

                                                                                                            type Builtin2

                                                                                                            type Builtin2 func(bctx BuiltinContext, op1, op2 *ast.Term) (*ast.Term, error)

                                                                                                              Builtin2 defines a built-in function that accepts 2 arguments.

                                                                                                              type Builtin3

                                                                                                              type Builtin3 func(bctx BuiltinContext, op1, op2, op3 *ast.Term) (*ast.Term, error)

                                                                                                                Builtin3 defines a built-in function that accepts 3 argument.

                                                                                                                type Builtin4

                                                                                                                type Builtin4 func(bctx BuiltinContext, op1, op2, op3, op4 *ast.Term) (*ast.Term, error)

                                                                                                                  Builtin4 defines a built-in function that accepts 4 argument.

                                                                                                                  type BuiltinContext

                                                                                                                  type BuiltinContext = topdown.BuiltinContext

                                                                                                                    BuiltinContext contains additional attributes from the evaluator that built-in functions can use, e.g., the request context.Context, caches, etc.

                                                                                                                    type BuiltinDyn

                                                                                                                    type BuiltinDyn func(bctx BuiltinContext, terms []*ast.Term) (*ast.Term, error)

                                                                                                                      BuiltinDyn defines a built-in function that accepts a list of arguments.

                                                                                                                      type CompileContext

                                                                                                                      type CompileContext struct {
                                                                                                                      	// contains filtered or unexported fields
                                                                                                                      }

                                                                                                                        CompileContext contains options for Compile calls.

                                                                                                                        type CompileOption

                                                                                                                        type CompileOption func(*CompileContext)

                                                                                                                          CompileOption defines a function to set options on Compile calls.

                                                                                                                          func CompilePartial

                                                                                                                          func CompilePartial(yes bool) CompileOption

                                                                                                                            CompilePartial defines an option to control whether partial evaluation is run before the query is planned and compiled.

                                                                                                                            type CompileResult

                                                                                                                            type CompileResult struct {
                                                                                                                            	Bytes []byte `json:"bytes"`
                                                                                                                            }

                                                                                                                              CompileResult represents the result of compiling a Rego query, zero or more Rego modules, and arbitrary contextual data into an executable.

                                                                                                                              type Errors

                                                                                                                              type Errors []error

                                                                                                                                Errors represents a collection of errors returned when evaluating Rego.

                                                                                                                                func (Errors) Error

                                                                                                                                func (errs Errors) Error() string

                                                                                                                                type EvalContext

                                                                                                                                type EvalContext struct {
                                                                                                                                	// contains filtered or unexported fields
                                                                                                                                }

                                                                                                                                  EvalContext defines the set of options allowed to be set at evaluation time. Any other options will need to be set on a new Rego object.

                                                                                                                                  type EvalOption

                                                                                                                                  type EvalOption func(*EvalContext)

                                                                                                                                    EvalOption defines a function to set an option on an EvalConfig

                                                                                                                                    func EvalDisableInlining

                                                                                                                                    func EvalDisableInlining(paths []ast.Ref) EvalOption

                                                                                                                                      EvalDisableInlining returns an argument that adds a set of paths to exclude from partial evaluation inlining.

                                                                                                                                      func EvalInput

                                                                                                                                      func EvalInput(input interface{}) EvalOption

                                                                                                                                        EvalInput configures the input for a Prepared Query's evaluation

                                                                                                                                        func EvalInstrument

                                                                                                                                        func EvalInstrument(instrument bool) EvalOption

                                                                                                                                          EvalInstrument enables or disables instrumenting for a Prepared Query's evaluation

                                                                                                                                          func EvalInterQueryBuiltinCache

                                                                                                                                          func EvalInterQueryBuiltinCache(c cache.InterQueryCache) EvalOption

                                                                                                                                            EvalInterQueryBuiltinCache sets the inter-query cache that built-in functions can utilize during evaluation.

                                                                                                                                            func EvalMetrics

                                                                                                                                            func EvalMetrics(metric metrics.Metrics) EvalOption

                                                                                                                                              EvalMetrics configures the metrics for a Prepared Query's evaluation

                                                                                                                                              func EvalParsedInput

                                                                                                                                              func EvalParsedInput(input ast.Value) EvalOption

                                                                                                                                                EvalParsedInput configures the input for a Prepared Query's evaluation

                                                                                                                                                func EvalParsedUnknowns

                                                                                                                                                func EvalParsedUnknowns(unknowns []*ast.Term) EvalOption

                                                                                                                                                  EvalParsedUnknowns returns an argument that sets the values to treat as unknown during partial evaluation.

                                                                                                                                                  func EvalPartialNamespace

                                                                                                                                                  func EvalPartialNamespace(ns string) EvalOption

                                                                                                                                                    EvalPartialNamespace returns an argument that sets the namespace to use for partial evaluation results. The namespace must be a valid package path component.

                                                                                                                                                    func EvalQueryTracer

                                                                                                                                                    func EvalQueryTracer(tracer topdown.QueryTracer) EvalOption

                                                                                                                                                      EvalQueryTracer configures a tracer for a Prepared Query's evaluation

                                                                                                                                                      func EvalResolver

                                                                                                                                                      func EvalResolver(ref ast.Ref, r resolver.Resolver) EvalOption

                                                                                                                                                        EvalResolver sets a Resolver for a specified ref path for this evaluation.

                                                                                                                                                        func EvalRuleIndexing

                                                                                                                                                        func EvalRuleIndexing(enabled bool) EvalOption

                                                                                                                                                          EvalRuleIndexing will disable indexing optimizations for the evaluation. This should only be used when tracing in debug mode.

                                                                                                                                                          func EvalSortSets

                                                                                                                                                          func EvalSortSets(yes bool) EvalOption

                                                                                                                                                            EvalSortSets causes the evaluator to sort sets before returning them as JSON arrays.

                                                                                                                                                            func EvalTime

                                                                                                                                                            func EvalTime(x time.Time) EvalOption

                                                                                                                                                              EvalTime sets the wall clock time to use during policy evaluation. time.now_ns() calls will return this value.

                                                                                                                                                              func EvalTracer

                                                                                                                                                              func EvalTracer(tracer topdown.Tracer) EvalOption

                                                                                                                                                                EvalTracer configures a tracer for a Prepared Query's evaluation Deprecated: Use EvalQueryTracer instead.

                                                                                                                                                                func EvalTransaction

                                                                                                                                                                func EvalTransaction(txn storage.Transaction) EvalOption

                                                                                                                                                                  EvalTransaction configures the Transaction for a Prepared Query's evaluation

                                                                                                                                                                  func EvalUnknowns

                                                                                                                                                                  func EvalUnknowns(unknowns []string) EvalOption

                                                                                                                                                                    EvalUnknowns returns an argument that sets the values to treat as unknown during partial evaluation.

                                                                                                                                                                    type ExpressionValue

                                                                                                                                                                    type ExpressionValue struct {
                                                                                                                                                                    	Value    interface{} `json:"value"`
                                                                                                                                                                    	Text     string      `json:"text"`
                                                                                                                                                                    	Location *Location   `json:"location"`
                                                                                                                                                                    }

                                                                                                                                                                      ExpressionValue defines the value of an expression in a Rego query.

                                                                                                                                                                      func (*ExpressionValue) String

                                                                                                                                                                      func (ev *ExpressionValue) String() string

                                                                                                                                                                      type Function

                                                                                                                                                                      type Function struct {
                                                                                                                                                                      	Name    string
                                                                                                                                                                      	Decl    *types.Function
                                                                                                                                                                      	Memoize bool
                                                                                                                                                                      }

                                                                                                                                                                        Function represents a built-in function that is callable in Rego.

                                                                                                                                                                        type Location

                                                                                                                                                                        type Location struct {
                                                                                                                                                                        	Row int `json:"row"`
                                                                                                                                                                        	Col int `json:"col"`
                                                                                                                                                                        }

                                                                                                                                                                          Location defines a position in a Rego query or module.

                                                                                                                                                                          type PartialQueries

                                                                                                                                                                          type PartialQueries struct {
                                                                                                                                                                          	Queries []ast.Body    `json:"queries,omitempty"`
                                                                                                                                                                          	Support []*ast.Module `json:"modules,omitempty"`
                                                                                                                                                                          }

                                                                                                                                                                            PartialQueries contains the queries and support modules produced by partial evaluation.

                                                                                                                                                                            type PartialResult

                                                                                                                                                                            type PartialResult struct {
                                                                                                                                                                            	// contains filtered or unexported fields
                                                                                                                                                                            }

                                                                                                                                                                              PartialResult represents the result of partial evaluation. The result can be used to generate a new query that can be run when inputs are known.

                                                                                                                                                                              func (PartialResult) Rego

                                                                                                                                                                              func (pr PartialResult) Rego(options ...func(*Rego)) *Rego

                                                                                                                                                                                Rego returns an object that can be evaluated to produce a query result.

                                                                                                                                                                                type PrepareConfig

                                                                                                                                                                                type PrepareConfig struct {
                                                                                                                                                                                	// contains filtered or unexported fields
                                                                                                                                                                                }

                                                                                                                                                                                  PrepareConfig holds settings to control the behavior of the Prepare call.

                                                                                                                                                                                  type PrepareOption

                                                                                                                                                                                  type PrepareOption func(*PrepareConfig)

                                                                                                                                                                                    PrepareOption defines a function to set an option to control the behavior of the Prepare call.

                                                                                                                                                                                    func WithNoInline

                                                                                                                                                                                    func WithNoInline(paths []string) PrepareOption

                                                                                                                                                                                      WithNoInline adds a set of paths to exclude from partial evaluation inlining.

                                                                                                                                                                                      func WithPartialEval

                                                                                                                                                                                      func WithPartialEval() PrepareOption

                                                                                                                                                                                        WithPartialEval configures an option for PrepareForEval which will have it perform partial evaluation while preparing the query (similar to rego.Rego#PartialResult)

                                                                                                                                                                                        type PreparedEvalQuery

                                                                                                                                                                                        type PreparedEvalQuery struct {
                                                                                                                                                                                        	// contains filtered or unexported fields
                                                                                                                                                                                        }

                                                                                                                                                                                          PreparedEvalQuery holds the prepared Rego state that has been pre-processed for subsequent evaluations.

                                                                                                                                                                                          func (PreparedEvalQuery) Eval

                                                                                                                                                                                          func (pq PreparedEvalQuery) Eval(ctx context.Context, options ...EvalOption) (ResultSet, error)

                                                                                                                                                                                            Eval evaluates this PartialResult's Rego object with additional eval options and returns a ResultSet. If options are provided they will override the original Rego options respective value. The original Rego object transaction will *not* be re-used. A new transaction will be opened if one is not provided with an EvalOption.

                                                                                                                                                                                            func (PreparedEvalQuery) Modules

                                                                                                                                                                                            func (pq PreparedEvalQuery) Modules() map[string]*ast.Module

                                                                                                                                                                                            type PreparedPartialQuery

                                                                                                                                                                                            type PreparedPartialQuery struct {
                                                                                                                                                                                            	// contains filtered or unexported fields
                                                                                                                                                                                            }

                                                                                                                                                                                              PreparedPartialQuery holds the prepared Rego state that has been pre-processed for partial evaluations.

                                                                                                                                                                                              func (PreparedPartialQuery) Modules

                                                                                                                                                                                              func (pq PreparedPartialQuery) Modules() map[string]*ast.Module

                                                                                                                                                                                              func (PreparedPartialQuery) Partial

                                                                                                                                                                                              func (pq PreparedPartialQuery) Partial(ctx context.Context, options ...EvalOption) (*PartialQueries, error)

                                                                                                                                                                                                Partial runs partial evaluation on the prepared query and returns the result. The original Rego object transaction will *not* be re-used. A new transaction will be opened if one is not provided with an EvalOption.

                                                                                                                                                                                                type Rego

                                                                                                                                                                                                type Rego struct {
                                                                                                                                                                                                	// contains filtered or unexported fields
                                                                                                                                                                                                }

                                                                                                                                                                                                  Rego constructs a query and can be evaluated to obtain results.

                                                                                                                                                                                                  Example (Custom_function_caching)
                                                                                                                                                                                                  Output:
                                                                                                                                                                                                  
                                                                                                                                                                                                  
                                                                                                                                                                                                  x: 1
                                                                                                                                                                                                  y: 1
                                                                                                                                                                                                  
                                                                                                                                                                                                  Example (Custom_function_global)
                                                                                                                                                                                                  Output:
                                                                                                                                                                                                  
                                                                                                                                                                                                  
                                                                                                                                                                                                  [foo bar baz]
                                                                                                                                                                                                  
                                                                                                                                                                                                  Example (Custom_functional_builtin)
                                                                                                                                                                                                  Output:
                                                                                                                                                                                                  
                                                                                                                                                                                                  
                                                                                                                                                                                                  [foo bar baz]
                                                                                                                                                                                                  

                                                                                                                                                                                                  func New

                                                                                                                                                                                                  func New(options ...func(r *Rego)) *Rego

                                                                                                                                                                                                    New returns a new Rego object.

                                                                                                                                                                                                    func (*Rego) Compile

                                                                                                                                                                                                    func (r *Rego) Compile(ctx context.Context, opts ...CompileOption) (*CompileResult, error)

                                                                                                                                                                                                      Compile returns a compiled policy query.

                                                                                                                                                                                                      func (*Rego) Eval

                                                                                                                                                                                                      func (r *Rego) Eval(ctx context.Context) (ResultSet, error)

                                                                                                                                                                                                        Eval evaluates this Rego object and returns a ResultSet.

                                                                                                                                                                                                        Example (Compiler)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        len: 1
                                                                                                                                                                                                        value: true
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (Errors)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        code: rego_unsafe_var_error
                                                                                                                                                                                                        row: 3
                                                                                                                                                                                                        filename: example_error.rego
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (Input)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        len: 2
                                                                                                                                                                                                        bindings.idx: 1
                                                                                                                                                                                                        bindings.user_id: alice
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (MultipleBindings)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        len: 2
                                                                                                                                                                                                        err: <nil>
                                                                                                                                                                                                        bindings["x"]: ex (i=0)
                                                                                                                                                                                                        bindings["x"]: ple (i=1)
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (MultipleDocuments)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        len: 2
                                                                                                                                                                                                        err: <nil>
                                                                                                                                                                                                        bindings["x"]: hello (i=0)
                                                                                                                                                                                                        value: alice (i=0)
                                                                                                                                                                                                        bindings["x"]: goodbye (i=1)
                                                                                                                                                                                                        value: bob (i=1)
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (Simple)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        len: 1
                                                                                                                                                                                                        bindings: map[x:1]
                                                                                                                                                                                                        err: <nil>
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (SingleDocument)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        value: [hello world]
                                                                                                                                                                                                        err: <nil>
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (Storage)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        value: [dogs clouds]
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (Trace_simple)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        query:1     Enter x = 1
                                                                                                                                                                                                        query:1     | Eval x = 1
                                                                                                                                                                                                        query:1     | Exit x = 1
                                                                                                                                                                                                        query:1     Redo x = 1
                                                                                                                                                                                                        query:1     | Redo x = 1
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (Tracer)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        query:1     Enter x = 1
                                                                                                                                                                                                        query:1     | Eval x = 1
                                                                                                                                                                                                        query:1     | Exit x = 1
                                                                                                                                                                                                        query:1     Redo x = 1
                                                                                                                                                                                                        query:1     | Redo x = 1
                                                                                                                                                                                                        
                                                                                                                                                                                                        Example (Transactions)
                                                                                                                                                                                                        Output:
                                                                                                                                                                                                        
                                                                                                                                                                                                        
                                                                                                                                                                                                        value (inside txn): pepperoni
                                                                                                                                                                                                        value (outside txn): cheese
                                                                                                                                                                                                        value (after txn): pepperoni
                                                                                                                                                                                                        

                                                                                                                                                                                                        func (*Rego) Partial

                                                                                                                                                                                                        func (r *Rego) Partial(ctx context.Context) (*PartialQueries, error)

                                                                                                                                                                                                          Partial runs partial evaluation on r and returns the result.

                                                                                                                                                                                                          Example
                                                                                                                                                                                                          Output:
                                                                                                                                                                                                          
                                                                                                                                                                                                          
                                                                                                                                                                                                          Query #1: "GET" = input.method; input.path = ["reviews", _]; input.is_admin
                                                                                                                                                                                                          Query #2: "GET" = input.method; input.path = ["reviews", user3]; user3 = input.user
                                                                                                                                                                                                          

                                                                                                                                                                                                          func (*Rego) PartialEval

                                                                                                                                                                                                          func (r *Rego) PartialEval(ctx context.Context) (PartialResult, error)

                                                                                                                                                                                                            PartialEval has been deprecated and renamed to PartialResult.

                                                                                                                                                                                                            func (*Rego) PartialResult

                                                                                                                                                                                                            func (r *Rego) PartialResult(ctx context.Context) (PartialResult, error)

                                                                                                                                                                                                              PartialResult partially evaluates this Rego object and returns a PartialResult.

                                                                                                                                                                                                              Example
                                                                                                                                                                                                              Output:
                                                                                                                                                                                                              
                                                                                                                                                                                                              
                                                                                                                                                                                                              input 1 allowed: true
                                                                                                                                                                                                              input 2 allowed: false
                                                                                                                                                                                                              input 3 allowed: true
                                                                                                                                                                                                              

                                                                                                                                                                                                              func (*Rego) PrepareForEval

                                                                                                                                                                                                              func (r *Rego) PrepareForEval(ctx context.Context, opts ...PrepareOption) (PreparedEvalQuery, error)

                                                                                                                                                                                                                PrepareForEval will parse inputs, modules, and query arguments in preparation of evaluating them.

                                                                                                                                                                                                                Example
                                                                                                                                                                                                                Output:
                                                                                                                                                                                                                
                                                                                                                                                                                                                
                                                                                                                                                                                                                initial result: false
                                                                                                                                                                                                                updated result: true
                                                                                                                                                                                                                

                                                                                                                                                                                                                func (*Rego) PrepareForPartial

                                                                                                                                                                                                                func (r *Rego) PrepareForPartial(ctx context.Context, opts ...PrepareOption) (PreparedPartialQuery, error)

                                                                                                                                                                                                                  PrepareForPartial will parse inputs, modules, and query arguments in preparation of partially evaluating them.

                                                                                                                                                                                                                  Example
                                                                                                                                                                                                                  Output:
                                                                                                                                                                                                                  
                                                                                                                                                                                                                  
                                                                                                                                                                                                                  First evaluation
                                                                                                                                                                                                                  Query #1: "GET" = input.method; input.path = ["reviews", _]; input.is_admin
                                                                                                                                                                                                                  Query #2: "GET" = input.method; input.path = ["reviews", user3]; user3 = input.user
                                                                                                                                                                                                                  Second evaluation
                                                                                                                                                                                                                  Query #1: input.path = ["reviews", _]; input.is_admin
                                                                                                                                                                                                                  Query #2: input.path = ["reviews", user3]; user3 = input.user
                                                                                                                                                                                                                  

                                                                                                                                                                                                                  type Result

                                                                                                                                                                                                                  type Result struct {
                                                                                                                                                                                                                  	Expressions []*ExpressionValue `json:"expressions"`
                                                                                                                                                                                                                  	Bindings    Vars               `json:"bindings,omitempty"`
                                                                                                                                                                                                                  }

                                                                                                                                                                                                                    Result defines the output of Rego evaluation.

                                                                                                                                                                                                                    type ResultSet

                                                                                                                                                                                                                    type ResultSet []Result

                                                                                                                                                                                                                      ResultSet represents a collection of output from Rego evaluation. An empty result set represents an undefined query.

                                                                                                                                                                                                                      type Vars

                                                                                                                                                                                                                      type Vars map[string]interface{}

                                                                                                                                                                                                                        Vars represents a collection of variable bindings. The keys are the variable names and the values are the binding values.

                                                                                                                                                                                                                        func (Vars) WithoutWildcards

                                                                                                                                                                                                                        func (v Vars) WithoutWildcards() Vars

                                                                                                                                                                                                                          WithoutWildcards returns a copy of v with wildcard variables removed.

                                                                                                                                                                                                                          Source Files