From 12da577eef4df026cded41a024027a7816e3fa71 Mon Sep 17 00:00:00 2001 From: Gaga Pan Date: Tue, 23 Jun 2020 12:14:58 +0800 Subject: [PATCH] docs/content: fix go integration example 1. module should be policy string above 2. pass context instance for .Eval also add decision output in the example Fixes #2367 Signed-off-by: Gaga Pan --- docs/content/integration.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/content/integration.md b/docs/content/integration.md index 95071cd66c..910f192a28 100644 --- a/docs/content/integration.md +++ b/docs/content/integration.md @@ -179,6 +179,28 @@ parameterized with different options like the query, policy module(s), data store, etc. ```go + +module := ` +package example.authz + +default allow = false + +allow { + some id + input.method = "GET" + input.path = ["salary", id] + input.subject.user = id +} + +allow { + is_admin +} + +is_admin { + input.subject.groups[_] = "admin" +} +` + query, err := rego.New( rego.Query("x = data.example.authz.allow"), rego.Module("example.rego", module), @@ -202,7 +224,8 @@ input := map[string]interface{}{ }, } -results, err := query.Eval(context.Context, rego.EvalInput(input)) +ctx := context.TODO() +results, err := query.Eval(ctx, rego.EvalInput(input)) ``` The `rego.PreparedEvalQuery#Eval` function returns a _result set_ that contains @@ -221,6 +244,7 @@ if err != nil { // Handle unexpected result type. } else { // Handle result/decision. + // fmt.Printf("%+v", results) => [{Expressions:[true] Bindings:map[x:true]}] } ```